trimws: Remove Leading/Trailing Whitespace

Description Usage Arguments Details Examples

Description

Remove leading and/or trailing whitespace from character strings.

Usage

1
trimws(x, which = c("both", "left", "right"))

Arguments

x

a character vector

which

a character string specifying whether to remove both leading and trailing whitespace (default), or only leading ("left") or trailing ("right"). Can be abbreviated.

Details

For portability, ‘whitespace’ is taken as the character class [ \t\r\n] (space, horizontal tab, line feed, carriage return).

Examples

1
2
3
4
5
x <- "  Some text. "
x
trimws(x)
trimws(x, "l")
trimws(x, "r")

Questions? Problems? Suggestions? or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.