Learn R Programming

Ecfun (version 0.2-0)

grepNonStandardCharacters: grep for nonstandard characters

Description

Return the indices of elements of x containing characters that are not in standardCharacters.

Usage

grepNonStandardCharacters(x, value=FALSE,
   standardCharacters=c(letters, LETTERS, ' ','.', ',', 0:9,
      '\"', "\'", '-', '_', '(', ')', '[', ']', '\n'),
   ... )

Arguments

x

character vector in which it is desired to identfy elements containing characters not in standardCharacters.

value

logical: TRUE to return the values found in x, FALSE to return their indices.

standardCharacters

Characters to overlook in x to identify anything not in standardCharacters.

optional arguments for regexpr

Value

an integer vector identifying all elements of x containing a character not in standardCharacters.

Details

1. x. <- strsplit(x, ''): convert the input character vector to a list of vectors of character vectors with nchar(x.[i]) == 1 for i in 1:length(x).

2. sapply(x., ...) to identify all elements for which any element of x[[i]] is not in standardCharacters.

See Also

stringi-package grep, regexpr, subNonStandardCharacters, showNonASCII

Examples

Run this code
# NOT RUN {
Names <- c('Raul', 'Ra`l', 'Torres,Raul', 'Torres, Raul')
#  confusion in character sets can create
#  names like Names[2]

chk <- grepNonStandardCharacters(Names)

# }
# NOT RUN {
all.equal(chk, 2)
# }
# NOT RUN {
chkv <- grepNonStandardCharacters(Names, TRUE)

# }
# NOT RUN {
all.equal(chkv, 'Ra`l')
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab