powered by
Truncate a string to a fixed of characters, so that str_length(str_trunc(x, n)) is always less than or equal to n.
str_length(str_trunc(x, n))
n
str_trunc(string, width, side = c("right", "left", "center"), ellipsis = "...")
A character vector the same length as string.
string
Input vector. Either a character vector, or something coercible to one.
Maximum width of string.
Location and content of ellipsis that indicates content has been removed.
str_pad() to increase the minimum width of a string.
str_pad()
x <- "This string is moderately long" rbind( str_trunc(x, 20, "right"), str_trunc(x, 20, "left"), str_trunc(x, 20, "center") )
Run the code above in your browser using DataLab