This function shortens given character strings so they are not longer than a given maximum length.
shortenStrings(strings, maxLength = 25, minLength = 10,
split = " ", fixed = TRUE,
ellipsis = "...", countEllipsisInLength = FALSE)Character strings to be shortened.
Maximum length (number of characters) in the strings to be retained. See details for when the returned strings can exceed this length.
Minimum length of the returned strings. See details.
Character string giving the split at which the strings can be truncated. This can be a literal string or a
regular expression (if the latter, fixed below must be set to FALSE).
Logical: should split be interpreted as a literal specification (TRUE) or as a regular
expression (FALSE)?
Character string that will be appended to every shorten string, to indicate that the string has been shortened.
Logical: should the length of the ellipsis count toward the minimum and maximum length?
A character vector of strings, shortened as necessary. If the input strings had non-NULL dimensions
and dimnames, these are copied to the output.
Strings whose length (number of characters) is at most maxLength are returned unchanged. For those
that are longer, the function uses gregexpr to search for the occurrences of split in
each given
character string. If such occurrences are found at positions between minLength and maxLength,
the string will be truncated at the last such split; otherwise, the string will be truncated at
maxLength. The ellipsis is appended to each truncated string.
gregexpr, the workhorse pattern matching function
formatLabels for splitting strings into multiple lines