shortenStrings | R Documentation |
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)
strings |
Character strings to be shortened. |
maxLength |
Maximum length (number of characters) in the strings to be retained. See details for when the returned strings can exceed this length. |
minLength |
Minimum length of the returned strings. See details. |
split |
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 |
Logical: should |
ellipsis |
Character string that will be appended to every shorten string, to indicate that the string has been shortened. |
countEllipsisInLength |
Logical: should the length of the ellipsis count toward the minimum and maximum length? |
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.
A character vector of strings, shortened as necessary. If the input strings
had non-NULL dimensions
and dimnames, these are copied to the output.
Peter Langfelder
gregexpr
, the workhorse pattern matching function
formatLabels
for splitting strings into multiple lines
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.