strip | R Documentation |
Removes any character that is not alphanumeric or a space.
(Disabled by default): Remove numbers.
Reduces multiple consecutive whitespaces to a single whitespace and trims ends.
Can for instance be used to simplify error messages before checking them.
strip( strings, replacement = "", remove_spaces = FALSE, remove_numbers = FALSE, remove_ansi = TRUE, lowercase = FALSE, allow_na = TRUE )
strings |
|
replacement |
What to replace blocks of punctuation with. (Character) |
remove_spaces |
Whether to remove all whitespaces. (Logical) |
remove_numbers |
Whether to remove all numbers. (Logical) |
remove_ansi |
Whether to remove ANSI control sequences. (Logical) |
lowercase |
Whether to make the strings lowercase. (Logical) |
allow_na |
Whether to allow |
ANSI control sequences are removed with fansi::strip_ctl()
.
gsub("[^[:alnum:][:blank:]]", replacement, strings))
gsub('[0-9]+', '', strings)
(Note: only if specified!)
trimws( gsub("[[:blank:]]+", " ", strings) )
(Or ""
if remove_spaces
is TRUE
)
The stripped strings.
Ludvig Renbo Olsen, r-pkgs@ludvigolsen.dk
Other strippers:
strip_msg()
# Attach packages library(xpectr) strings <- c( "Hello! I am George. \n\rDon't call me Frank! 123", " \tAs that, is, not, my, name!" ) strip(strings) strip(strings, remove_spaces = TRUE) strip(strings, remove_numbers = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.