title: Writing a function and calling variable in a data frame R
body: <p>I am trying to write a function with an argument that calls a variable from a data frame and I am wondering why the use of <code>with()</code> doesn't work in this instance?</p>
  
  <pre><code>#Data
  N=100
  p=2
  d=data.frame(matrix(rbinom(N*p,1,.5),N,p))
  
  #Trivial fxn 1
  fxn1=function(var,data){
      # SELECT DATA
      data.new = data[with(data,var)==0,]
      return(data.new)}
  
  fxn1(x1,d)   #doesn't work
  fxn1(d$x1,d) # works
  </code></pre>
  
  <p><em>Note1:</em> I asked this question: <a href="https://stackoverflow.com/questions/29609830/what-are-the-advantages-of-using-with-vs-calling-vectors">What are the advantages of using with() vs. calling vectors?</a> awhile back and it seems like this would be a perfect use of <code>with</code> (but apparently it's not).</p>
  
  <p><em>Note2:</em> I also asked this question: <a href="https://stackoverflow.com/questions/30467890/call-variable-from-custom-function">Call variable from custom function</a> and received a useful answer which led me to write this function which does work: </p>
  
  <pre><code>fxn2=function(var,data){
      data.new=data[data[[deparse(substitute(var))]]==0,]
      return (data.new)}
  
  fxn2(x1,d) #works
  </code></pre>