Escape the special characters in a string
fix_escaping.Rd
This function adds the designated number of escape characters (\
) before special characters.
Usage
fix_escaping(
text,
special_chars = c("(", ")", ".", "{", "}", "[", "]"),
num_escapes = 2,
use.names = F
)
Arguments
- text
A character string to process.
- special_chars
A character vector of special characters that need escaping. Defaults are "
.
", "(
", "{
","}
", "[
", "]
", and ")
"- num_escapes
Integer. Required number of
\
before special character.- use.names
Boolean Should a named list with preserved name be returned. Default is
FALSE
.
Examples
if (FALSE) { # \dontrun{
rgx <- fix_escaping("This (is) (a) test.", special_chars = c("(", ")", "?"), num_escapes = 4)
# Returns: "This \\(is\\) \\(a\\) test."
} # }