title: dplyr ifelse mutate reference to variable outside the data frame
body: <p>I have a simple problem but i haven't figured out the solution yet. I don't know how to reference to a variable outside the data frame when I'm using dplyr. Here is a small chunk of code:</p>
  <pre><code>library(dplyr)
  
  var &lt;- 1
  
  df &lt;- data.frame(col1 = c(&quot;a&quot;, &quot;b&quot;, &quot;c&quot;), col2 = c(1, 2, 3))
  
  df %&gt;% mutate(col2 = ifelse(var == 1, col2 + var, col2))
  </code></pre>
  <p>Result:</p>
  <pre><code>  col1 col2
  1    a    2
  2    b    2
  3    c    2
  </code></pre>
  <p>Desired output:</p>
  <pre><code>  col1 col2
  1    a    2
  2    b    3
  3    c    4
  
   
  </code></pre>