title: How to rename multiple strings and skip errors if it doesn't apply
body: <p>I am trying to take a list of free-form text entries of names, some of which have been mispelled, some not, but I want them all to be rewritten in the exact way.  I've written a number of possible mispellings and want it set up so that if a particular mispelling is found, it renames it, otherwise the code should move on without stopping.</p>
  <p>So for example:</p>
  <pre><code>names[names$Response %in% c(&quot;j trudeau&quot;, &quot;justni trudeau&quot;, &quot;justin truduae&quot;),]$Response = &quot;justin trudeau&quot;
  names[names$Response %in% c(&quot;emmanuelle macron&quot;),]$Response = &quot;emmanuel macron&quot;
  </code></pre>
  <p>If I go through the lines of code one-by-one and run them manually, the renaming works just fine--although it does show errors if one of the proposed mispellings is not found. But if I use &quot;Run All&quot;, the error stops the code from proceeding. I'd like to be able to send the file to another users machine and have the code run properly, even if a particular mispelling isn't there.</p>
  <p>I was hoping to use the functions try() or tryCatch() to skip over the error messages, but it seems like they can't be used for this sort of subsetting. Does this scenario call for something like <code>str_replace_all</code> from package &quot;<code>stringr</code>&quot;? Ideally, I want to be able to make code that is as short and simple as possible, since there are a ton of names to standardise. Is there some other very obvious solution I'm overlooking?</p>
  <p>Thanks in advance for any help.</p>