str_trunc: Truncate a string to maximum width

View source: R/trunc.R

str_truncR Documentation

Truncate a string to maximum width

Description

Truncate a string to a fixed of characters, so that str_length(str_trunc(x, n)) is always less than or equal to n.

Usage

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

Arguments

string

Input vector. Either a character vector, or something coercible to one.

width

Maximum width of string.

side, ellipsis

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

Value

A character vector the same length as string.

See Also

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

Examples

x <- "This string is moderately long"
rbind(
  str_trunc(x, 20, "right"),
  str_trunc(x, 20, "left"),
  str_trunc(x, 20, "center")
)

stringr documentation built on Nov. 15, 2023, 1:08 a.m.