R-alpha: dump() / dput() -- fail for "environmental" and attributed functions

Martin Maechler Martin Maechler <maechler@stat.math.ethz.ch>
Wed, 8 Oct 1997 10:51:35 +0200

Here is a simple example to show what I mean:

	f1 <- approxfun(1:3, 2:4)

	dump("f1", file="")

which yields (in current development snapshot; 
	      other versions are conceptually equivalent)

"f1" <-
function (v) 
.C("approx", as.double(x), as.double(y), n, xout = as.double(v), 
        length(v), as.integer(method), as.double(yleft), as.double(yright), 
        as.double(f), NAOK = T)$xout

i.e., the 'environment' part is not dumped.

Probably, we can well live without this working.
However, dump(.) or dput(.) then should produce a warning or error.

But the problem is more general:
In newer versions of R  functions can have attributes,
(including a "class") -- which is very useful as already mentionend here.

However, even these are NOT dumped properly, and they SHOULD be!

fa <- function(x) x + 1
attr(fa, "class") <- "simple.fun"

#-- results (wrongly) in

 function (x) 
 x + 1

i.e. `forgets' about the class attribute which you see when printing fa.
r-devel 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-devel-request@stat.math.ethz.ch