How to escape a question mark in R?

r, regex

Solution

You have to escape `\` as well:

vectorOfStrings <- c("Where is Waldo?", "I don't know", "This is ? random ?")
grep("\\?", vectorOfStrings)
#-----
[1] 1 3

Problem

I am trying to grep a vector of strings and some of them contain question marks. I am doing: `grep('\?',vectorofStrings)` and getting this error: `Error: '\?' is an unrecognized escape in character string starting "\?"` How can I determine the proper escaping procedure for '?'

Original source