Learn R Programming

WGCNA (version 1.70-3)

shortenStrings: Shorten given character strings by truncating at a suitable separator.

Description

This function shortens given character strings so they are not longer than a given maximum length.

Usage

shortenStrings(strings, maxLength = 25, minLength = 10, 
              split = " ", fixed = TRUE,
              ellipsis = "...", countEllipsisInLength = FALSE)

Arguments

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 below must be set to FALSE).

fixed

Logical: should split be interpreted as a literal specification (TRUE) or as a regular expression (FALSE)?

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?

Value

A character vector of strings, shortened as necessary. If the input strings had non-NULL dimensions and dimnames, these are copied to the output.

Details

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.

See Also

gregexpr, the workhorse pattern matching function formatLabels for splitting strings into multiple lines