title: gsub inside function with mutate called in dplyr chain gives error
body: <p>I have the following example data (the real data contains other columns with both numeric and character variables):</p>
  
  <pre><code>structure(list(AM = structure(1:20, .Label = c("AMP_R", "AZI_R", 
  "CHL_R", "CIP_R", "COL_R", "ERY_R", "ETP_R", "F.C_R", "FEP_R", 
  "FOT_R", "FOX_R", "GEN_R", "IMI_R", "MERO_R", "NAL_R", "STR_R", 
  "SULFA_R", "T.C_R", "TAZ_R", "TET_R"), class = "factor")), .Names = "AM", row.names = c(NA, 
  -20L), class = "data.frame")
  </code></pre>
  
  <p>I tried to create a function that will detect whether or not a column in a data frame contains variables with the ending "_R". If they do, it will remove this ending and proceed with renaming the variables to full names, accoring to a conversion table. If the "_R" ending is not present, it will just convert the names directly.</p>
  
  <p>I have tried the following on the first part of the function:</p>
  
  <pre><code>library(dplyr)
  
  convert_AM_names &lt;- function(data, col) {
      data %&gt;%
        mutate(col = gsub("(.*?)_R", "\\1", col))
  }
  </code></pre>
  
  <p>I want to use it in a dplyr chain, like this:</p>
  
  <pre><code>AM &lt;- AM %&gt;%
    rowwise() %&gt;%
    convert_AM_names(., AM)
  </code></pre>
  
  <p>However, when I do this, it gives the error "Error in mutate_impl(.data, dots): Column "col" must be length 1, not 20"</p>
  
  <p>I saw that similar issues have been addressed here at SO, but for most of them the solution was to use rowwise(), which doesn't seem to work here. Any suggestions?</p>