str_trunc: Truncate a character string.

Description Usage Arguments See Also Examples

Description

Truncate a character string.

Usage

1
2
str_trunc(string, width, side = c("right", "left", "center"),
  ellipsis = "...")

Arguments

string

A character vector.

width

Maximum width of string.

side, ellipsis

Location and content of ellipsis that indicates content has been removed.

See Also

str_pad() to increase the minimum width of a string.

Examples

1
2
3
4
5
6
x <- "This string is moderately long"
rbind(
  str_trunc(x, 20, "right"),
  str_trunc(x, 20, "left"),
  str_trunc(x, 20, "center")
)

Example output

     [,1]                  
[1,] "This string is mo..."
[2,] "...s moderately long"
[3,] "This stri...ely long"

stringr documentation built on May 2, 2019, 11:03 a.m.