Abbreviate strings to at least
such that they remain unique (if they were),
strict = TRUE.
1 2 3
a character vector of names to be abbreviated, or an
object to be coerced to a character vector by
the minimum length of the abbreviations.
logical: should lowercase characters be removed first?
logical: should a dot (
a character string specifying the method used with default
The default algorithm (
method = "left.kept") used is similar
to that of S. For a single string it works as follows.
First spaces at the ends of the string are stripped.
Then (if necessary) any other spaces are stripped.
Next, lower case vowels are removed followed by lower case consonants.
Finally if the abbreviation is still longer than
upper case letters and symbols are stripped.
Characters are always stripped from the end of the strings first. If
an element of
names.arg contains more than one word (words are
separated by spaces) then at least one letter from each word will be
NA) values are unaltered.
FALSE then the only distinction is to
be between letters and space.
A character vector containing abbreviations for the character strings
in its first argument. Duplicates in the original
will be given identical abbreviations. If any non-duplicated elements
have the same
minlength abbreviations then, if
"both.sides" the basic internal
abbreviate() algorithm is
applied to the characterwise reversed strings; if there are
still duplicated abbreviations and if
strict = FALSE as by
minlength is incremented by one and new abbreviations
are found for those elements only. This process is repeated until all
unique elements of
names.arg have unique abbreviations.
names is true, the character version of
attached to the returned value as a
names attribute: no
other attributes are retained.
If a input element contains non-ASCII characters, the corresponding
value will be in UTF-8 and marked as such (see
use.classes is true (the default), this is really only
suitable for English, and prior to R 3.3.0 did not work correctly
with non-ASCII characters in multibyte locales. It will warn if used
with non-ASCII characters (and required to reduce the length).
As from R 3.3.0 the concept of ‘vowel’ is extended from English vowels by including characters which are accented versions of lower-case English vowels (including ‘o with stroke’). Of course, there are languages (even Western European languages such as Welsh) with other vowels.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
x <- c("abcd", "efgh", "abce") abbreviate(x, 2) abbreviate(x, 2, strict = TRUE) # >> 1st and 3rd are == "ab" (st.abb <- abbreviate(state.name, 2)) stopifnot(identical(unname(st.abb), abbreviate(state.name, 2, named=FALSE))) table(nchar(st.abb)) # out of 50, 3 need 4 letters : as <- abbreviate(state.name, 3, strict = TRUE) as[which(as == "Mss")] ## and without distinguishing vowels: st.abb2 <- abbreviate(state.name, 2, FALSE) cbind(st.abb, st.abb2)[st.abb2 != st.abb, ] ## method = "both.sides" helps: no 4-letters, and only 4 3-letters: st.ab2 <- abbreviate(state.name, 2, method = "both") table(nchar(st.ab2)) ## Compare the two methods: cbind(st.abb, st.ab2)