title: Scoping and functions in R 2.11.1 : What's going wrong?
body: <p>This question comes from a range of other questions that all deal with essentially the same problem. For some strange reason, using a function within another function sometimes fails in the sense that variables defined within the local environment of the first function are not found back in the second function.</p>
  
  <p>The classical pattern in pseudo-code :</p>
  
  <pre><code>ff &lt;- function(x){
      y &lt;- some_value
      some_function(y)
  }
  ff(x)
  </code></pre>
  
  <blockquote>
    <p>Error in eval(expr, envir, enclos) :
    object 'y' not found</p>
  </blockquote>
  
  <p>First I thought it had something to do with S4 methods and the scoping in there, but it also happens with other functions. I've had some interaction with the R development team, but all they did was direct me to the bug report site (which is not the most inviting one, I have to say). I never got any feedback.</p>
  
  <p>As the problem keeps arising, I wonder if there is a logic explanation for it. Is it a common mistake made in all these cases, and if so, which one? Or is it really a bug? </p>
  
  <p>Some of those questions :</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/2646402/using-functions-and-environments">Using functions and environments</a></li>
  <li><a href="https://stackoverflow.com/questions/3742415/r-statistical-scoping-error-using-transformby-part-of-the-doby-package">R (statistical) scoping error using transformBy(), part of the doBy package.</a></li>
  <li><a href="https://stackoverflow.com/questions/3768417/how-to-use-acast-reshape2-within-a-function-in-r">How to use acast (reshape2) within a function in R?</a></li>
  <li><a href="https://stackoverflow.com/questions/3661500/why-cant-i-pass-a-dataset-to-a-function">Why can't I pass a dataset to a function?</a></li>
  <li><a href="https://stackoverflow.com/questions/3574858/values-not-being-copied-to-the-next-local-environment">Values not being copied to the next local environment</a></li>
  </ul>
  
  <p>PS : I know the R-devel list, in case you wondered...</p>