remove_space | R Documentation |
Remove leading/trailing spaces and normalize multiple spaces between words in character strings.
remove_space(
x,
trim_start = TRUE,
trim_end = FALSE,
collapse_multiple = TRUE,
preserve_newlines = TRUE
)
x |
A vector of character strings. |
trim_start |
Logical value, default is 'TRUE'. Whether to remove leading spaces before the first word. |
trim_end |
Logical value, default is 'FALSE'. Whether to remove trailing spaces after the last word. |
collapse_multiple |
Logical value, default is 'TRUE'. Whether to collapse multiple consecutive spaces between words into a single space. |
preserve_newlines |
Logical value, default is 'TRUE'. Whether to preserve newline characters when collapsing spaces. |
A character vector with spaces normalized according to the specified parameters.
x <- c(
" hello world ",
" test case ",
"no space",
" multiple spaces "
)
remove_space(x)
remove_space(x, trim_start = FALSE)
remove_space(x, trim_end = TRUE)
remove_space(x, collapse_multiple = FALSE)
remove_space(
x,
trim_start = FALSE,
trim_end = FALSE,
collapse_multiple = FALSE
)
# with newlines
multiline <- c(
"hello\n\n world ",
" first \n second "
)
remove_space(multiline)
remove_space(multiline, preserve_newlines = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.