Learn R Programming

berryFunctions (version 1.22.5)

removeSpace: Remove white spaces from strings

Description

Remove leading and/or trailing white space from character strings

Usage

removeSpace(x, begin = TRUE, end = TRUE, all = FALSE, ...)

Value

Character string (vector)

Arguments

x

Character string, can be a vector

begin

Logical. Remove leading spaces at the beginning of the character string? DEFAULT: TRUE

end

Logical. Remove trailing spaces at the end? DEFAULT: TRUE

all

Logical. Remove all spaces anywhere in the string? DEFAULT: FALSE

...

Further arguments passed to sub or gsub, like ignore.case, perl, fixed, useBytes.

Author

Berry Boessenkool, berry-b@gmx.de, Dec 2014

See Also

sub, trimws since R 3.2.0 (April 2015)

Examples

Run this code

s <- c("space at end     ", "  white at begin", "  both ", " special ^  ")
removeSpace(s)
trimws(s)

# To add space, use:
x <- c("ab","abcde")
format(x)
format(x, justify="centre")
format(x, width=9)

Run the code above in your browser using DataLab