From cubranic at stat.ubc.ca  Mon Jul 18 22:58:53 2011
From: cubranic at stat.ubc.ca (Davor Cubranic)
Date: Mon, 18 Jul 2011 13:58:53 -0700
Subject: [Rd] Fwd: Understanding R's "Environment" concept
In-Reply-To: <CA+A3Hr5F7BG-DpwfcptauzejJ2_m3i9SgWCCn=HMTO7eXPyQqA@mail.gmail.com>
References: <CA+A3Hr6MrAOxNk3L9DZp_CQ-323J6g1efs0q+Apgk6U2OEDmJw@mail.gmail.com>
	<CA+A3Hr5F7BG-DpwfcptauzejJ2_m3i9SgWCCn=HMTO7eXPyQqA@mail.gmail.com>
Message-ID: <88F55755-CBDD-4804-B2EA-CCB0130F5B39@stat.ubc.ca>

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


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