[R] Suimmary of answers : Possible (ab)use of lexical scoping in R ?

Uwe Ligges ligges at statistik.uni-dortmund.de
Sun May 22 12:58:20 CEST 2005


Emmanuel Charpentier wrote:
> Dear List,
> 
> I asked how to create a set of functions (and maybe variables) shared by
> another set of functions but hidden from the "main" environment.
> 
> Duncan Murdoch and Brian Ripley advised to use the package creation
> system. Brian ripley (and someone else, offlist) also pointed me to the
> local() function, which creates new environments with specified
> contents, and which I was unaware of (btw, when this function has been
> introduced ? It is mentioned neither in MASS 4th edition index, nor in
> 'S Programming' index).

I think everybody remembers that local() has been introduced in R-0.65.0 
(those who do not remember can simply look into the file OONEWS).

I like the two books as well, but I don't think they can be complete in 
the sense of describing *all* R functions.

I'd like to recommend the "package way". Working with envrionments and 
local() does not seem to be the R way - and it is very confusing to read 
code that refers to a couple of different environments ...

Uwe Ligges



> After re-reading the available docs (which I may have misunderstood...),
> I come to the following conclusions :
> 
> 	- The package creation is the most elegant and portable form. Unless I
> am mistaken, it entails however some administrative overhead (creation
> of a directory structure, R CMD installation*, etc ...).
> 
> 	- Using local() is a (semi-) kludge, easy to use in one-file disposable
> works. It might be more error-prone than package creation.
> 
> 	- It has been pointed to me that manipulating environment (via local()
> or otherwise), in a very Abelson-&-Sussmann-like way, allowed to create
> OO-oriented code, somewhat different from S3 and S4 class mechanisms.
> 
> Since repeated experiences have proved to my satisfaction that I am
> piss-poor at top-down design, I will probably use the environment
> manipulation for initial head-scratching phase, switching to package
> creation at the formalization phase.
> 
> A big "thank you" to all respondents, whose answers have been *very* useful.
> 
> 					Emmanuel Charpentier
>




More information about the R-help mailing list