title: How to mutate with ifelse within a function
body: <p>I am trying to create a function using ifelse but keep getting an error message. I want to create a flag variable that populates a 1 if both of two variables = <code>abs(1)</code>, and a 0 otherwise</p>
  
  <p>I can get code to run by inputting 2 specific variables, but am having trouble turning that into a function. Any help is appreciated! </p>
  
  <pre><code>#this is the code I got to work
  df &lt;- df %&gt;%
  mutate(Flag=ifelse(PTO_1== abs(1) &amp;&amp; PTO_2 == abs(1), 1, 0))
  
  #now trying to turn it into a function
  flag &lt;- function(var1,var2) {
  df &lt;- df %&gt;%
  mutate(Flag=ifelse(var1== abs(1) &amp;&amp; var2 == abs(1), 1, 0))
  }
  
  #trying out the function, and get an error message
  flag(PTO_1,PTO_2)
  </code></pre>
  
  <p>I expect a new 'flag' variable to be created, but instead get an error message: </p>
  
  <blockquote>
    <p>object 'PTO_1' not found</p>
  </blockquote>