[R] terminology for frames and environments

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

On Mon, 14 Jun 2004, John Maindonald wrote:
> I have found it helpful, in trying to explain (to myself and others)
> what happens, to say that there is both a lexical stack and a call
> stack.  Is that a legitimate use of terminology?

I think this is helpful, despite being inaccurate.  If you also recognise
that there are multiple "lexical stacks" then it is an even better

Regarding "parent", the problem is that in S the term "parent frame" was
used, quite reasonably, for the calling frame, resulting in the function
sys.parent(). Backwards (?sideways) compatibility requires that
sys.parent() exist in R and return a position in the calling stack, and
this led to parent.frame() as a shortcut for sys.frame(sys.parent()).
Unfortunately in R, "parent" would more logically refer to the lexical
parent, which is the rationale for parent.env().

That's why the situation is a mess.

I think the standard, given these contradictions, is
  "enclosing environment" for the lexical parent
  "parent environment" for the thing returned by parent.frame()
and that's what the FAQ uses in discussing scoping.

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).

In almost all sitations you can just think of a calling stack and a
lexical stack, and ignore the frame/environment distinction.  You do need
to be aware that this is an abuse of notation, because it does sometimes


More information about the R-help mailing list