Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

str_trunc

Truncate a character string.


Description

Truncate a character string.

Usage

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

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

stringr

Simple, Consistent Wrappers for Common String Operations

v1.4.0
GPL-2 | file LICENSE
Authors
Hadley Wickham [aut, cre, cph], RStudio [cph, fnd]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.