strip: strip all whitespace

Description Usage Arguments Details Value Examples

View source: R/char.r

Description

could do this with regular expression, but slow, and this function is called frequently. My only use case works with removal of all space character whitespace, and I don't expect <TAB>. This uses non-unicode aware matching for speed. This can be changed by setting useBytes to FALSE.

Usage

1
strip(x, pattern = " ", useBytes = TRUE)

Arguments

x

is a character vector to strip

pattern

is the non-regex of the character to strip, default " "

useBytes

logical scalar. Unlike gsub, this will default to TRUE here, therefore breaking unicode.

Details

gsub is probably quicker than stringr/stringi. For comorbidity processing, this package prefers the faster base functions, whereas stringr is used for tasks which are not time critical, e.g. parsing source data to be included in the distributed icd package.

Value

character vector

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
## Not run: 
requireNamespace("microbenchmark")
requireNamespace("stringr")
x <- random_string(25000)
microbenchmark::microbenchmark(
  gsub(x = x, pattern = "A", replacement = "", fixed = TRUE, useBytes = TRUE),
  gsub(x = x, pattern = "A", replacement = "", fixed = TRUE, useBytes = TRUE, perl = TRUE),
  gsub(x = x, pattern = "A", replacement = ""),
  stringr::str_replace_all(x, "A", "")
)

## End(Not run)

jackwasey/jwutil documentation built on Jan. 20, 2020, 6:56 p.m.