Learn R Programming

ThomasJeffersonUniv (version 0.1.3)

trimws_: Remove Leading/Trailing and Duplicated (Symbols that Look Like) White Spaces

Description

To remove leading/trailing and duplicated (symbols that look like) white spaces.

More aggressive than function trimws.

Usage

trimws_(x)

Value

Function trimws_ returns an object of typeof

character.

Arguments

x

an object with typeof being character

Details

Function trimws_ is more aggressive than trimws, that it removes

  • duplicated white spaces

  • symbols that look like white space, such as \u00a0 (no-break space)

Examples

Run this code
(x = c(A = ' a  b  ', b = 'a .  s', ' a  ,  b ; ', '\u00a0  ab '))
base::trimws(x)
# raster::trim(x) # do not want to 'Suggests'
trimws_(x)

(xm = matrix(x, nrow = 2L))
trimws_(xm)

#library(microbenchmark)
#microbenchmark(trimws(x), trimws_(x))

Run the code above in your browser using DataLab