formatLabels: Break long character strings into multiple lines

Description Usage Arguments Details Value Author(s) Examples

View source: R/Functions.R

Description

This function attempts to break lomg character strings into multiple lines by replacing a given pattern by a newline character.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
formatLabels(
   labels, 
   maxCharPerLine = 14, 
   maxWidth = NULL,
   maxLines = Inf,
   cex = 1,
   split = " ", 
   fixed = TRUE, 
   newsplit = split,
   keepSplitAtEOL = TRUE, 
   capitalMultiplier = 1.4,
   eol = "\n", 
   ellipsis = "...")

Arguments

labels

Character strings to be formatted.

maxCharPerLine

Integer giving the maximum number of characters per line.

maxWidth

Maximum width in user coordinates. If given, overrides maxCharPerLine above and usually gives a much more efficient formatting.

maxLines

Maximum lines to retain. If a label extends past the maximum number of lines, ellipsis is added at the end of the last line.

cex

Character expansion factor that the user intends to use when adding labels to the current figure. Only used when maxWidth is specified.

split

Pattern to be replaced by newline ('\n') characters.

fixed

Logical: Should the pattern be interpreted literally (TRUE) or as a regular expression (FALSE)? See strsplit and its argument fixed.

newsplit

Character string to replace the occurrences of split above with.

keepSplitAtEOL

When replacing an occurrence of split with a newline character, should the newsplit be added before the newline as well?

capitalMultiplier

A multiplier for capital letters which typically occupy more space than lowercase letters.

eol

Character string to separate lines in the output.

ellipsis

Chararcter string to add to the last line if the input label is longer than fits on maxLines lines.

Details

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 (adjusted using the capital letter multiplier) of the combined result from the start or the previous newline character exceeds maxCharPerLine, or strwidth exceeds maxWidth, the character specified by eol 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.

Value

A character vector of the same length as input labels.

Author(s)

Peter Langfelder

Examples

1
2
s = "A quick hare jumps over the brown fox";
formatLabels(s);

nosarcasm/WGCNA documentation built on May 28, 2019, 1:01 p.m.