| chr.trunc | R Documentation |
This function truncates a character vector, so that the number of characters
of each element of the character vector is always less than or equal to the
width specified in the argument width.
chr.trunc(x, width, side = c("right", "left", "center"), ellipsis = "...",
check = TRUE)
x |
a character vector or factor. Note that factors are converted into a character vector. |
width |
a numeric value indicating the maximum width of the character
strings in the vector. Note that the default setting
switches to |
side |
a character string indicating the location of the ellipsis,
i.e. |
ellipsis |
a character string indicating the content of the ellipsis,
i.e., |
check |
logical: if |
Returns a truncated character vector.
This function was adapted from the str_trunc() function in the stringr
package by Hadley Wickham (2023).
Takuya Yanagida
Wickham H (2023). stringr: Simple, Consistent Wrappers for Common String Operations. R package version 1.5.1, https://CRAN.R-project.org/package=stringr
chr.color, chr.grep, chr.grepl,
chr.gsub, chr.omit, chr.trim
# Example 1: Truncate at the right side with a max. of 10 characters
chr.trunc(row.names(mtcars), width = 10)
# Example 2: Truncate at the left side with a max. of 10 characters
chr.trunc(row.names(mtcars), width = 10, side = "left")
# Example 3: Truncate without ellipses
chr.trunc(row.names(mtcars), width = 10, ellipsis = "")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.