[R] save.image() excluding functions

Thomas Lumley tlumley at u.washington.edu
Fri Feb 22 18:06:35 CET 2002


On Fri, 22 Feb 2002, Agustin Lobo wrote:
>
> If the recommendation is to write functions with an external editor
> (I mean, avoiding fix()), keep them as text files (*.R) and using
> source() to bring them into the R session, why not excluding,
> by default, function objects from save.image() ?
> In particular, from the final save.image(),
> the one that is proposed at q().
>
> In this way, functions would not get included within .RData,


There's a number of problems with excluding functions from .RData.
Primarily

1/ compatibility. The S languages have never distinguished between
functions and other forms of data in this way.

2/ Functions cannot necessarily be stored as text. They have
environments, which could in principle reference any amount of data. The
only completely reliable way for R to store a function is using save().
You as the author of a function can know that the environment is
irrelevant but it's quite hard for R to know this (Luke Tierney's
proposed byte-code compiler needs to be able to tell, so this may change)


In fact the most common recommendation is not just that functions should
be defined in external files but that everything else should be as well.
>From that viewpoint .RData is just a convenient scratchpad to store
intermediate results without having to re-run them, and it really has to
contain the entire state of the program.

Anyone who really wants to modify save.image() in their own copy of R can
do so, but I think it's unlikely that this change would be popular as a
default.


	-thomas

Thomas Lumley			Asst. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list