This function attempts to break lomg character strings into multiple lines by replacing a given pattern by a newline character.
formatLabels(labels,
maxCharPerLine = 14,
split = " ", fixed = TRUE,
newsplit = split, keepSplitAtEOL = TRUE)
Character strings to be formatted.
Integer giving the maximum number of characters per line.
Pattern to be replaced by newline ('\n') characters.
Logical: Should the pattern be interpreted literally (TRUE
) or as a regular expression (FALSE
)?
See strsplit
and its argument fixed
.
Character string to replace the occurrences of split
above with.
When replacing an occurrence of split
with a newline character, should the newsplit
be added
before the newline as well?
A character vector of the same length as input labels
.
Each given element of labels
is processed independently. The character string is split using
strsplit
, with split
as the splitting pattern. The resulting shorter character strings are
then concatenated together with newsplit
as the separator. Whenever the length of the combined
result from the start or the previous newline character exceeds maxCharPerLine
, a newline character
is inserted (at the previous split).
Note that individual segements (i.e., sections of the input between occurrences of split
) whose
number of characters exceeds maxCharPerLine
will not be split.
# NOT RUN {
s = "A quick hare jumps over the brown fox";
formatLabels(s);
# }
Run the code above in your browser using DataLab