title: Why doesn't dplyr filter() work within function (i.e. using variable for column name)?
body: <p>A function for filtering, grouping and mutating data with dplyr functions. Basic pipe sequence works great outside a function, that is where I use the true column names. Put it in a function where the column name is a variable and some of the functions work but some don't most notably dplyr::filter(). For example:</p>
  
  <pre><code>var1 &lt;- c('yes', NA, NA, 'yes', 'yes', NA, NA, NA, 'yes', NA, 'no', 'no', 'no', 'maybe', NA, 'maybe', 'maybe', 'maybe')
  
  var2 &lt;- c(1:18)
  
  df &lt;- data.frame(var1, var2)
  </code></pre>
  
  <p>This works fine (i.e. filters NA's):</p>
  
  <pre><code>df%&gt;%filter(!is.na(var1))
  </code></pre>
  
  <p>...but this doesn't:</p>
  
  <pre><code>x &lt;- "var1"
  
  df%&gt;%filter(!is.na(x))
  </code></pre>
  
  <p>...but this does:</p>
  
  <pre><code>df%&gt;%select(x)
  </code></pre>
  
  <p>It's NA's that need to be filtered out specifically.</p>
  
  <p>Tried get("x"), no good, and slicing:</p>
  
  <pre><code>df[!is.na(x),]
  </code></pre>
  
  <p>...no good, either.</p>
  
  <p>Any ideas on how to pass a variable to filter inside (or outside) a function and why a variable is working with other dplyr functions?</p>