trimws | R Documentation |
Removes whitespaces (or other code points as specified by the
whitespace
argument) from left, right, or both sides of each string.
trimws(x, which = "both", whitespace = "\\p{Wspace}")
x |
character vector whose elements are to be trimmed |
which |
single string; either |
whitespace |
single string; specifies the set of Unicode code points for removal, see 'Character Classes' in about_search_regex for more details |
Not to be confused with strtrim
.
Returns a character vector (in UTF-8).
Replacement for base trimws
implemented with stri_replace_all_regex
(and not stri_trim
, which uses a slightly different
syntax for pattern specifiers).
the default whitespace
argument does not reflect the
'contemporary' definition of whitespaces
(e.g., does not include zero-width spaces)
[fixed here]
base R implementation is not portable as it is based on
the system PCRE library
(e.g., some Unicode classes may not be available or matching thereof
can depend on the current LC_CTYPE
category)
[fixed here]
no sanity checks are performed on whitespace
[fixed here]
The official online manual of stringx at https://stringx.gagolewski.com/
Related function(s): sub
base::trimws("NAAAAANA!!!NANAAAAA", whitespace=NA) # stringx raises an error
x <- " :)\v\u00a0 \n\r\t"
base::trimws(x)
stringx::trimws(x)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.