title: Non standard evaluation from another function in R
body: <p>Here is an example from Hadley's advanced R book:</p>
  
  <pre><code>sample_df &lt;- data.frame(a = 1:5, b = 5:1, c = c(5, 3, 1, 4, 1))
  
  subset2 &lt;- function(x, condition) {
    condition_call &lt;- substitute(condition)
    r &lt;- eval(condition_call, x, parent.frame())
    x[r, ]
  }
  
  scramble &lt;- function(x) x[sample(nrow(x)), ]
  
  subscramble &lt;- function(x, condition) {
    scramble(subset2(x, condition))
  }
  
  subscramble(sample_df, a &gt;= 4)
  # Error in eval(expr, envir, enclos) : object 'a' not found
  </code></pre>
  
  <p>Hadley explains:</p>
  
  <blockquote>
    <p>Can you see what the problem is? condition_call contains the expression condition. So when we evaluate condition_call it also evaluates condition, which has the value a >= 4. However, this can’t be computed because there’s no object called a in the parent environment. </p>
  </blockquote>
  
  <p>I understand that there is no <code>a</code> in the parent env, but, <code>eval(condition_call, x, parent.frame())</code> evals conditional_call in x (a data.frame used as an environment), enclosed by <code>parent.frame()</code>. As long as there is a column named <code>a</code> in x, why should there be any problem?</p>