[R] terminology for frames and environments

Thomas Lumley tlumley at u.washington.edu
Mon Jun 14 22:49:16 CEST 2004


On Mon, 14 Jun 2004, Gabor Grothendieck wrote:

> Thomas Lumley <tlumley <at> u.washington.edu> writes:
>
> > The distinction between "environment" and "frame" is important. The frame
> > is what you find things in with get(, inherits=FALSE) and the environment
> > uses get(, environment=TRUE).
>
> The thing I find odd about this one is that if we have:
>
> e <- new.env()
> e$x <- 1
> f <- new.env(parent=e)
> f$x  # gives an error
>
> then I would have expected x to be returned since f is an environment
> and x is in that environment.  On the other hand, if an environment
> is defined to be the same as a frame (and there is some other word for
> an environment and its ancestors) then the above notation makes sense.
>

Maybe. On the other hand, $ *is* documented to look only in the first
frame of the environment.  It only doesn't make sense if you think of an
environment as a flat vector.  If you think of the nested structure then
it does make sense and is analogous to what happens with more complicated
lists and expressions.

If you had
   e<-quote(b*x)
   f<- substitute(a+tmp,list(tmp=e))
x would not appear as an element of f, but would appear as an element of
an element (yes, I do realise the tree is upside-down compared to an tree
of environments).

	-thomas




More information about the R-help mailing list