how to paste the "backslash-dot" (\.)combo in R?

r, regex

Solution

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

Problem

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!

Original source