I have a string in R, e.g. x <- "c:\tmp\rest.zip". How can I detect that it has escape sequences in it, vis. \t and \r? Us DOS/Windows guys have a habit of using backslashes that R doesn't like and I'm writing a function where I would like to be able to protect the user from themselves.
Thanks.
Doubling of the back-slashes in the grep pattern is the path to success:
xtxt <- c("test\n", "of\t", "escapes")
grep("\\n|\\t", xtxt)
# [1] 1 2
Another way to be to search for control characters:
grep("[[:cntrl:]]", xtxt)
#[1] 1 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With