title: gsub in dplyr mutate ifelse statement returning first item rather than selected items
body: <p>I want to run a mutate selectively, given a variable input. The mutate needs to then run a gsub on a chr column. For example:</p>
  <pre><code>thing &lt;- &quot;yes&quot;
  
  starwars %&gt;% mutate(homeworld = 
                      ifelse(thing == &quot;yes&quot;, 
                             gsub(&quot;oo&quot;, &quot;_&quot;, homeworld), 
                             homeworld)) %&gt;%
              select(name, homeworld)
  </code></pre>
  <p>gsub in the above code appears to perform the substitution on the first item of homeworld and replace all homeworld values with this:</p>
  <pre><code>   name               homeworld
     &lt;chr&gt;              &lt;chr&gt;    
   1 Luke Skywalker     Tat_ine  
   2 C-3PO              Tat_ine  
   3 R2-D2              Tat_ine  
   4 Darth Vader        Tat_ine 
  </code></pre>
  <p>When I would expect:</p>
  <pre><code>   name               homeworld
     &lt;chr&gt;              &lt;chr&gt;    
   1 Luke Skywalker     Tat_ine  
   2 C-3PO              Tat_ine  
   3 R2-D2              Nab_
   4 Darth Vader        Tat_ine 
  </code></pre>
  <p>This works if I don't include the ifelse statement:</p>
  <pre><code>starwars %&gt;% mutate(homeworld = gsub(&quot;oo&quot;, &quot;_&quot;, homeworld))
  </code></pre>