Skip to content
Prev 30972 / 398506 Next

lexical scope

Dear Robin,

In terms of documentation I have found John Fox's "Frames, environments, and 
scope in R and S-PLUS" (available at
http://socserv.socsci.mcmaster.ca/jfox/Books/companion/appendix-scope.pdf) to 
be an excellent document. 

"Lexical scope and statistical computing" by Gentleman & Ihaka (at the J. 
Comp. Graph. Stat., 2000, 9: 491-508, though I think a pdf of a preprint can 
be found somewhere in the net) contains more general discussion and more 
ellaborate examples.

Finally, section 10.7 of "An introduction to R" has brief discussion of these 
issues, but that should answer the specific questions you asked.


With regards to your specific situation:
x is a "free variable" for f, and f will look for it in (at? I'll never get 
this right) the environment where it was defined (the global environment in 
your example).

When you call f from g, f still looks for x in the environment where it was 
defined; first time (before you rm(x)) x is 19 there; the second time, there 
is no x anymore.

This behavior is different from that of S-PLUS.

Hope this helps,

Ram?n
On Tuesday 22 April 2003 06:07, Robin Hankin wrote: