title: R: Functions -- Display of environment name instead of memory address of that environment?
body: <p>What is the way to display the name of the environment inside the function as like built-in functions? For example, when I type the function: mean available in base package, I can see the environment as "namespace:base".</p>
  
  <pre><code>mean
  
     function (x, ...) 
     UseMethod("mean")
     &lt;bytecode: 0x0547f17c&gt;
     **&lt;environment: namespace:base&gt;**
  </code></pre>
  
  <p>However, when I attach a function to the newly created environment, here to access the values for the free variable (z) inside the function (f), it automatically resides in .GlobalEnv environment and the name of the environment is not displayed inside the function, but the memory address "0x051abd60" of (e1) environment is seen. </p>
  
  <pre><code>     e1 &lt;- new.env()
       e1$z &lt;- 10
       f &lt;- function(x) {
             x + z 
        }
       environment(f) = e1
       f
  
                 function(x) {
                      x + z 
                 }
                 **&lt;environment: 0x051abd60&gt;**
  </code></pre>
  
  <p>Why do I see this behavior? Why don't I get my environment name inside the function as like built-in functions of R and also the functions available from various R packages? Is there a difference between environment data structure and .GlobalEnv environment available from search()</p>
  
  <p>Any pointers towards the motivation behind this behavior would be highly appreciated.</p>
  
  <p>Thank you</p>