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

Emmanuel Charpentier charpent at bacbuc.dyndns.org
Sun May 22 02:30:16 CEST 2005

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

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

Emmanuel Charpentier			charpent at bacbuc.dyndns.org

More information about the R-help mailing list