I\'m using R for genetic programming with the RGP package. The environment creates functions that solve problems. I want to save these functions in their own .R source files. I
While the question has already been answered, I should mention that dump
has some pitfalls and IMO you would be better off saving your function in binary format via save
.
In particular, dump
only saves the function code itself, not any associated environment. This may not be a problem here, but could bite you at some point. For example, suppose we have
e <- new.env()
e$x <- 10
f <- function(y) y + x
environment(f) <- e
Then dump("f")
will only save the function definition of f
, and not its environment. If you then source
the resulting file, f
will no longer work correctly. This doesn't happen if you use save
and load
.