Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

trim

Remove Leading and Trailing White Space


Description

Remove leading and/or trailing white space from character vectors.

Usage

trim(s, leading = TRUE, trailing = TRUE, perl = TRUE, ...)

Arguments

s

a character vector

leading

logical

trailing

logical

perl

logical

...

arguments passed to gsub

Details

trim removes leading and trailing space, which is defined through the (Perl) regular expression \s.

The base package has a function trimws these days, so you may not actually need the function (any more).

Value

a character vector

Author(s)

Enrico Schumann

See Also

Examples

s <- c("\t 2 2\n \t", "   ab  ")
trim(s)

textutils

Utilities for Handling Strings and Text

v0.2-1
GPL-3
Authors
Enrico Schumann [aut, cre] (<https://orcid.org/0000-0001-7601-6576>)
Initial release
2021-04-01

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.