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

Description Usage Arguments Details Value Author(s) See Also

View source: R/Functions.R

Description

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

Usage

1
2
3
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?

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.

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.

Author(s)

Peter Langfelder

See Also

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


WGCNA documentation built on March 1, 2021, 1:05 a.m.

Related to shortenStrings in WGCNA...