Ignore regular expression in grep pattern


Hello everyone please I have an issue with grep. I have an array of pattern which can have regular expression or not. when I grep the pattern on my corpus some of them are not found because they have regular expression. I don't know how to sove the problem. Can you help me please?


Could you please turn this into a self-contained reprex (short for reproducible example)? It will help us help you.


If you've never heard of a reprex before, you might want to start by reading the tidyverse.org help page. The reprex dos and don'ts are also useful.

What to do if you run into clipboard problems

If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste the contents into the forum.

reprex::reprex(input = "fruits_stringdist.R", outfile = "fruits_stringdist.md")

For pointers specific to the community site, check out the reprex FAQ, linked to below.


You could use mapply to vectorized the pattern and fixed arguments.

  FUN      = grepl,
  pattern  = c("^cat", "^cat", "c.t", "c.t"),
  fixed    = c(FALSE, TRUE, FALSE, TRUE),
  MoreArgs = list(x = "^cat")
#  ^cat  ^cat   c.t   c.t 

I'd suggest writing a function to handle this for you. How that functions works depends on your data and desired output.