View source: R/protectSpecChar.R
protectSpecChar | R Documentation |
Some characters do have a special meaning when used with regular expressions.
This concerns characters like a point, parinthesis, backslash etc.
Thus, when using grep
or any related command, shuch special characters must get protected in order to get considered as they are.
protectSpecChar(
x,
prot = c(".", "\\", "|", "(", ")", "[", "{", "^", "$", "*", "+", "?"),
silent = TRUE,
debug = FALSE,
callFrom = NULL
)
x |
character vector to be prepared for use in regular expressions |
prot |
(character) collection of characters that need to be protected |
silent |
(logical) suppress messages |
debug |
(logical) additional messages for debugging |
callFrom |
(character) allow easier tracking of messages produced |
This function returns a modified character vector
aa <- c("abc","abcde","ab.c","ab.c.e","ab*c","ab\\d")
grepl("b.", aa) # all TRUE
grepl("b\\.", aa) # manual prootection
grepl(protectSpecChar("b."), aa)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.