abbreviate_text: abbreviate_text

Description Usage Arguments Value See Also Examples

View source: R/abbreviate_text.R

Description

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.

Usage

1
abbreviate_text(txt, minlength = 3, alnum = TRUE)

Arguments

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: TRUE)

Value

abbreviated strings

See Also

base::abbreviate or package uniqtag

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# 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)

sigbertklinke/abbreviate documentation built on Dec. 23, 2021, 2:20 a.m.