title: Using rlang and map to recode many variables in R
body: <p>I am cleaning a data set and need to recode many factor variables. I would like to use <code>rlang</code> and <code>map</code> to create a function to do this. My example dataset and code are below. I think I almost got it, but I just can't seem to figure out the bug, probably because I don't fully grasp <code>rlang</code>.</p>
  
  <p>Working dataset:</p>
  
  <pre><code>df1 &lt;- tribble(
  ~var1, ~var2, ~var3,
  "1",   "1",   "1",
  "2",   "2",   "2",
  "3",   "3",   "3"
  )
  </code></pre>
  
  <p>Here is how I would recode a single variable (and the result I would like):</p>
  
  <pre><code>df1 &lt;- df1 %&gt;%
    mutate(var1 = fct_recode(var1,
                            "0" = "1",
                            "1" = "2",
                            "2" = "3")) 
  </code></pre>
  
  <p>Here is my working code:</p>
  
  <pre><code>recode = function(...){
    mutate_quo = quos(...)
  
    map(mutate_quo, ~{
      df1 &lt;- df1 %&gt;%
        mutate(!!.x = fct_recode(!!.x,
                           "0" = "1",
                           "1" = "2",
                           "2" = "3"))
    })
  }
  </code></pre>
  
  <p>This gives the following error:</p>
  
  <pre><code>Error: unexpected '=' in:
  "    df1 &lt;- df1 %&gt;%
    mutate(!!.x ="
  &gt;                              "0" = "1",
  Error: unexpected ',' in "                             "0" = "1","
  &gt;                              "1" = "2",
  Error: unexpected ',' in "                             "1" = "2","
  &gt;                              "2" = "3"))
  Error: unexpected ')' in "                             "2" = "3")"
  &gt;   })
  Error: unexpected '}' in "  }"
  &gt; }
  Error: unexpected '}' in "}"
  </code></pre>
  
  <p>If I remove the <code>!!</code>, the function will compile. However, when I then try to call it using <code>recode("var1")</code>, I get the following error:</p>
  
  <pre><code>Error in mutate_impl(.data, dots) : 
  Evaluation error: `f` must be a factor (or character vector).. 
  </code></pre>
  
  <p>I would like to have the function and then just run <code>recode(var1, var2, var3)</code>.</p>