Re: [R] Help with saving user defined functions

2017-02-12 Thread Bert Gunter
ecdf() is part of the stats package, which is (typically) automatically attached on startup. I have no idea what you mean by "splitting" and "saving." This is basically how all of R works -- e.g. see the value of lm() and the (S3) plot method, plot.lm, for "lm" objects. This has nothing to do wit

Re: [R] Help with saving user defined functions

2017-02-12 Thread George Trojan - NOAA Federal
I want to split my computation into parts. The first script processes the data, the second does the graphics. I want to save results of time-consuming calculations. My example tried to simulate this by terminate the session without saving it, so the environment was lost on purpose. What confuses m

Re: [R] Help with saving user defined functions

2017-02-12 Thread Bert Gunter
Jeff: Oh yes!-- and I meant to say so and forgot, so I'm glad you did. Not only might the free variable in the function not be there; worse yet, it might be there but something else. So it seems like a disaster waiting to happen. The solution, I would presume, is to have no free variables (make th

Re: [R] Help with saving user defined functions

2017-02-12 Thread Jeff Newmiller
So doesn't the fact that a function contains a reference to an environment suggest that this whole exercise is a really bad idea? -- Sent from my phone. Please excuse my brevity. On February 12, 2017 4:05:31 PM PST, Bert Gunter wrote: >It worked fine for me: > >> t <- rnorm(100) >> cdf <- ecdf(

Re: [R] Help with saving user defined functions

2017-02-12 Thread Bert Gunter
It worked fine for me: > t <- rnorm(100) > cdf <- ecdf(t) > > trans <- function(x) qnorm(cdf(x) * 0.99) > saveRDS(trans, "/tmp/foo") > trans(1.2) [1] 1.042457 > trans1 <- readRDS("/tmp/foo") > trans1(0) [1] 0.1117773 Of course, if I remove cdf() from the global environment, it will fail: > rm(c

[R] Help with saving user defined functions

2017-02-12 Thread George Trojan - NOAA Federal
I can't figure out how to save functions to RDS file. Here is an example what I am trying to achieve: > t <- rnorm(100) > cdf <- ecdf(t) > cdf(0) [1] 0.59 > saveRDS(cdf, "/tmp/foo") > Save workspace image? [y/n/c]: n [gtrojan@asok petproject]$ R > cdf <- readRDS("/tmp/foo") > cdf Empirical CDF Cal