trimws {stringx}R Documentation

Trim Leading or Trailing Whitespaces

Description

Removes whitespaces (or other code points as specified by the whitespace argument) from left, right, or both sides of each string.

Usage

trimws(x, which = "both", whitespace = "\\p{Wspace}")

Arguments

x

character vector whose elements are to be trimmed

which

single string; either "both", "left", or "right"; side(s) from which the code points matching the whitespace pattern are to be removed

whitespace

single string; specifies the set of Unicode code points for removal, see 'Character Classes' in about_search_regex for more details

Details

Not to be confused with strtrim.

Value

Returns a character vector (in UTF-8).

Differences from Base R

Replacement for base trimws implemented with stri_replace_all_regex (and not stri_trim, which uses a slightly different syntax for pattern specifiers).

Author(s)

Marek Gagolewski

See Also

The official online manual of stringx at https://stringx.gagolewski.com/

Related function(s): sub

Examples

base::trimws("NAAAAANA!!!NANAAAAA", whitespace=NA)  # stringx raises an error
x <- "   :)\v\u00a0 \n\r\t"
base::trimws(x)
stringx::trimws(x)


[Package stringx version 0.2.8 Index]