title: Is there an R function to escape a string for regex characters
body: <p>I'm wanting to build a regex expression substituting in some strings to search for, and so these string need to be escaped before I can put them in the regex, so that if the searched for string contains regex characters it still works.</p>
  
  <p>Some languages have functions that will do this for you (e.g. python <code>re.escape</code>: <a href="https://stackoverflow.com/a/10013356/1900520">https://stackoverflow.com/a/10013356/1900520</a>).  Does R have such a function?</p>
  
  <p>For example (made up function):</p>
  
  <pre><code>x = "foo[bar]"
  y = escape(x) # y should now be "foo\\[bar\\]"
  </code></pre>