tags:

views:

52

answers:

1

as title, I am working on some gregexpr in R now, I need to search for something start with a dot, so I need to use "." (without quote), but R keep saying that it is an unrecognized escape. What can I do?

Thanks!

+4  A: 

You need to escape the backslash.

> string <- c("foo","ba.r")
> grep("\.",string)
Error: '\.' is an unrecognized escape in character string starting "\."
> grep("\\.",string)
[1] 2
Joshua Ulrich