title: is.data.frame(data) object ... not found in function context
body: <p>Have a strange problem using package <code>tree</code> <code>cv.tree</code> function from user defined function in R:</p>
  
  <pre><code>func &lt;- function(train) {
      classification.tree &lt;- tree(log10(perf) ~ syct+mmin+mmax+cach+chmin+chmax, train, split = "gini")
      cv.tree(classification.tree, ,FUN=prune.tree, K = 4)
      return (classification.tree)
  }
  data(cpus, package="MASS")
  result &lt;- func(cpus)
  plot(result)
  </code></pre>
  
  <p>This produces the error:</p>
  
  <pre><code>Error in is.data.frame(data) : object 'train' not found 
  16 is.data.frame(data) 
  15 model.frame.default(formula = log10(perf) ~ syct + mmin + mmax + 
      cach + chmin + chmax, data = train, subset = c("1", "2", 
  "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", 
  "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25",  ... 
  14 eval(expr, envir, enclos) 
  13 eval(expr, p) 
  12 eval.parent(m) 
  11 tree(formula = log10(perf) ~ syct + mmin + mmax + cach + chmin + 
      chmax, data = train, split = "gini", subset = c("1", "2", 
  "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", 
  "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25",  ... 
  10 eval(expr, envir, enclos) 
  9 eval(oc) 
  8 model.frame.tree(object) 
  7 model.frame(object) 
  6 cv.tree(classification.tree, , FUN = prune.tree, K = 4) at .active-rstudio-document#4
  5 func(cpus) at .active-rstudio-document#9
  4 eval(expr, envir, enclos) 
  3 eval(ei, envir) 
  2 withVisible(eval(ei, envir)) 
  1 source("~/.active-rstudio-document", echo = TRUE) 
  </code></pre>
  
  <p>At the same time if I invoke same code right from the script it works perfectly fine:</p>
  
  <pre><code>data(cpus, package="MASS")
  classification.tree &lt;- tree(log10(perf) ~ syct+mmin+mmax+cach+chmin+chmax, cpus, split = "gini")
  cv.tree(classification.tree, ,FUN=prune.tree, K = 4)
  plot(classification.tree)
  </code></pre>
  
  <p>What am I missing?</p>