strip_invalid_chars

0th

Percentile

Removes invalid characters from a string.

Removes invalid characters from a string, leaving only digits.

Usage
strip_invalid_chars(x, invalid_chars, char_desc = gettext("invalid"))
strip_non_alphanumeric(x)
strip_non_numeric(x, allow_x = FALSE, allow_plus = FALSE)
Arguments
x
Input to strip.
invalid_chars
A regular expression detailing characters to remove.
char_desc
A string describing the characters to remove.
allow_x
If TRUE, the letter "X" is allowed - useful for check digits.
allow_plus
If TRUE, the symbol "+" is allowed - useful for phone numbers.
Value

A character vector of the same length as x, consisting of strings without the characters detailed in the invalid_chars.

Aliases
  • strip_invalid_chars
  • strip_non_alphanumeric
  • strip_non_numeric
Examples
library(assertive.strings) ## Not run: # strip_invalid_chars( # " We're floating\tin space\n\n\n", "[[:space:]]", "whitespace" # ) # strip_non_numeric(" +44 800-123-456 ", allow_plus = TRUE) # #Inputs such as factors as coerced to character. # strip_non_alphanumeric(factor(c(" A1\t1AA.", "*(B2^2BB)%"))) # ## End(Not run)
Documentation reproduced from package assertive.strings, version 0.0-3, License: GPL (>= 3)

Community examples

Looks like there are no examples yet.