| Title: | Readable String Abbreviation |
|---|---|
| Description: | Strings are abbreviated to at least "minlength" characters, such that they remain unique (if they were). The abbreviations should be recognisable. The algorithm does not guarantee that a always a solution is found. |
| Authors: | Sigbert Klinke [aut, cre] |
| Maintainer: | Sigbert Klinke <[email protected]> |
| License: | GPL-3 |
| Version: | 0.2 |
| Built: | 2026-05-19 06:24:39 UTC |
| Source: | https://github.com/sigbertklinke/abbreviate |
Shorten strings to at least minlength characters so that they remain unique (if they were).
Duplicate strings or NAs are allowed. Note that different orders in the string may result
in different abbreviations. Since the algorithm does not guarantee that unique abbreviations
will always be found, a warning is issued if the number of unique abbreviations and unique strings
is unequal.
abbreviate_text(txt, minlength = 3, alnum = TRUE)abbreviate_text(txt, minlength = 3, alnum = TRUE)
txt |
character: vector of strings to abbreviate |
minlength |
integer: the minimum length of the abbreviations |
alnum |
logical: should strings be reduced to alpha-numeric characters before abbreviation (default: |
abbreviated strings
base::abbreviate or package uniqtag
# unique with first letters is possible txt <- c("euclidean", "maximum", "manhattan", "canberra", "minimum") abbreviate_text(txt, 3) # if identical strings used then same abbreviation txt <- c("euclidean", "maximum", "manhattan", "manhattan", "canberra", "minimum") abbreviate_text(txt, 3) # NAs are allowed txt <- c("euclidean", "maximum", "manhattan", NA, "canberra", "minimum") abbreviate_text(txt, 3) # unique abbreviations txt <- c("ward.D", "ward.D2", "single", "complete", "average", "mcquitty", "median", "centroid") abbreviate_text(txt, 3) # unique abbreviations, but not really intuitive abbreviate_text(txt, 0)# unique with first letters is possible txt <- c("euclidean", "maximum", "manhattan", "canberra", "minimum") abbreviate_text(txt, 3) # if identical strings used then same abbreviation txt <- c("euclidean", "maximum", "manhattan", "manhattan", "canberra", "minimum") abbreviate_text(txt, 3) # NAs are allowed txt <- c("euclidean", "maximum", "manhattan", NA, "canberra", "minimum") abbreviate_text(txt, 3) # unique abbreviations txt <- c("ward.D", "ward.D2", "single", "complete", "average", "mcquitty", "median", "centroid") abbreviate_text(txt, 3) # unique abbreviations, but not really intuitive abbreviate_text(txt, 0)