[Rd] Fwd: Understanding R's "Environment" concept

Davor Cubranic cubranic at stat.ubc.ca
Mon Jul 18 22:58:53 CEST 2011


On 2011-07-18, at 11:52 AM, Nipesh Bajaj wrote:

> Hi all, I am trying to understand the R's "environment" concept
> however the underlying help files look quite technical to me. Can
> experts here provide me some more intuitive ideas behind this concept
> like, why it is there, what exactly it is doing in R's architecture
> etc.?

The "official" definition in the language manual (http://cran.r-project.org/doc/manuals/R-lang.html#Environment-objects) is quite technical, but this sentence makes intuitive sense as well:

    When R looks up the value for a symbol the frame is examined and if a matching symbol is found its value will be returned.

In other words, the environment holds all the defined values (variables, functions, etc.) and lets you refer to them by name. When you assign a value to a variable, say "x <- 10", this is stored in the environment. Then when the program is executed, when you refer to the name "x", it is looked up in the environment and replaced by its value there. (The reality is a little more complicated than that, but this is a close enough simplification.)

As for "why and what it's doing there", you will need to understand some programming language concepts first -- I don't think it's possible to explain this "non-technically".

Davor


More information about the R-devel mailing list