Learn R Programming

berryFunctions (version 1.21.2)

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, ...)

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.

Value

Character string (vector)

See Also

sub, trimws since R 3.2.0 (April 2015)

Examples

Run this code
# NOT RUN {
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