In R, how can you determine if a string contains escape sequences?

I have a string in R, for example. x <- "c: \ tmp \ rest.zip". How can I find that it has escape sequences in it, for example. \ t and \ r? We 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 myself.

Thank.

+5
source share
1 answer

Doubling backslashes in a grep pattern is the way to success:

 xtxt <- c("test\n", "of\t", "escapes")
 grep("\\n|\\t", xtxt)
# [1] 1 2

Another way to search for control characters:

 grep("[[:cntrl:]]", xtxt)
#[1] 1 2
+11
source

All Articles