StrTrunc: Truncate Strings and Add Ellipses If a String is Truncated.

Description Usage Arguments Value Author(s) See Also Examples

View source: R/DescTools.r

Description

Truncates one or more strings to a specified length, adding an ellipsis (...) to those strings that have been truncated. Use formatC to justify the strings if needed.

Usage

1
 StrTrunc(x, maxlen = 20)

Arguments

x

a vector of strings.

maxlen

the maximum length of the returned strings.

Value

The string(s) passed as x now with a maximum length of maxlen + 3 (for the ellipsis).

Author(s)

Andri Signorell,
following an idea of Jim Lemon in truncString()

See Also

String functions: nchar, match, grep, regexpr, substr, sub, gsub, StrTrim, StrDist

Examples

1
2
3
4
5
6
7
8
set.seed(1789)
x <- sapply(seq(10),  function(x) paste(sample(letters, sample(20,1)),collapse=""))
x

StrTrunc(x, maxlen=10)

# right justification
formatC(StrTrunc(x, maxlen=10), width = 10, flag=" ")

DescTools documentation built on Sept. 13, 2017, 9:04 a.m.