title: R How to remap letters in a string
body: <p>I’d be grateful for suggestions as to how to remap letters in strings in a map-specified way.</p>
  <p>Suppose, for instance, I want to change all As to Bs, all Bs to Ds, and all Ds to Fs.  If I do it like this, it doesn’t do what I want since it applies the transformations successively:</p>
  <pre><code>&quot;abc&quot; %&gt;% str_replace_all(c(a = &quot;b&quot;, b = &quot;d&quot;, d = &quot;f&quot;))
  </code></pre>
  <p>Here’s a way I <em>can</em> do what I want, but it feels a bit clunky.</p>
  <pre><code>f &lt;- function (str) str_c( c(a = &quot;b&quot;, b = &quot;d&quot;, c = &quot;c&quot;, d = &quot;f&quot;) %&gt;% .[ strsplit(str, &quot;&quot;)[[1]] ], collapse = &quot;&quot; )
  
  &quot;abc&quot; %&gt;% map_chr(f)
  </code></pre>
  <p>Better ideas would be much appreciated.</p>
  <p>James.</p>
  <p>P.S.  Forgot to specify.  Sometimes I want to replace a letter with multiple letters, e.g., replace all As with the string ZZZ.</p>
  <p>P.P.S.  Ideally, this would be able to handle vectors of strings too, e.g., c(&quot;abc&quot;, &quot;gersgaesg&quot;, etc.)</p>