[R] Understanding R's "Environment" concept
b.rowlingson at lancaster.ac.uk
Mon Jul 18 21:11:30 CEST 2011
On Mon, Jul 18, 2011 at 7:16 PM, Nipesh Bajaj <bajaj141003 at gmail.com> 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
> I mainly need some non-technical intuitive explanation.
You can think of it as a box into which you can put (using "assign")
and get (using "get") things.
Now, the interesting thing is that when you copy an environment, you
dont make a new copy of everything in it:
Now if I change 'foo' in z, as if by magic it changes in e as well:
> assign("foo","Set in z",env=z)
 "Set in z"
Because e and z are the same environment:
This gives you a way of doing pass-by-reference in R, but you won't be
doing it that way soon because R version something has proper
That's probably all you need to know to get you started.
More information about the R-help