title: Can't I use functions inside other functions in R?
body: <p>I've been having trouble understanding functions and environments, so I tried writing a simple function to simplify the problem. I wrote the following code:</p>
  
  <pre><code>h &lt;- c(1:5)
  meta &lt;- function(){
    resta &lt;- function(){
      v &lt;- h-2
      assign("h", v, envir = globalenv())
      h
    }
  } 
  </code></pre>
  
  <p>Now, when I call <code>resta()</code>, it takes <code>2</code> from <code>h</code>, shows me the result and changes its value in the global environment, but if I call <code>meta()</code> nothing at all happens, <code>h</code> doesn't change its value in the global environment. </p>
  
  <p>I also tried the <code>resta</code> function by itself (not inside another function) and it works just fine. </p>
  
  <p>Am I missing something? Is R not able to run functions like this? is there any explanation for this related to environments? </p>