Re: [Rd] Model object, when generated in a function, saves entire environment when saved

2020-01-30 Thread Harvey Smith
Depending on if you need the data in the referenced environments later, you could fit the model normally and use the refhook argument in saveRDS/readRDS to replace references to environments in the model with a dummy value. normal_lm <- function(){ junk <- runif(1e+08) lm(Sepal.Length ~ Sepa

Re: [Rd] Model object, when generated in a function, saves entire environment when saved

2020-01-29 Thread Duncan Murdoch
On 29/01/2020 2:25 p.m., Kenny Bell wrote: Reviving an old thread. I haven't noticed this be a problem for a while when saving RDS's which is great. However, I noticed the problem again when saving `qs` files (https://github.com/traversc/qs) which is an RDS replacement with a fast serialization /

Re: [Rd] Model object, when generated in a function, saves entire environment when saved

2020-01-29 Thread Kenny Bell
Reviving an old thread. I haven't noticed this be a problem for a while when saving RDS's which is great. However, I noticed the problem again when saving `qs` files (https://github.com/traversc/qs) which is an RDS replacement with a fast serialization / compression system. I'd like to get an idea

Re: [Rd] Model object, when generated in a function, saves entire environment when saved

2016-07-27 Thread Kenny Bell
Thanks so much for all this. The first solution is what I'm going with as I want the terms object to come along so that predict still works. On Wed, Jul 27, 2016 at 12:28 PM, William Dunlap via R-devel < r-devel@r-project.org> wrote: > Another solution is to only save the parts of the model obje

Re: [Rd] Model object, when generated in a function, saves entire environment when saved

2016-07-27 Thread William Dunlap via R-devel
Another solution is to only save the parts of the model object that interest you. As long as they don't include the formula (which is what drags along the environment it was created in), you will save space. E.g., tfun2 <- function(subset) { junk <- 1:1e6 list(subset=subset, lm(Sepal.Lengt

Re: [Rd] Model object, when generated in a function, saves entire environment when saved

2016-07-27 Thread Duncan Murdoch
On 27/07/2016 1:48 PM, Kenny Bell wrote: In the below, I generate a model from an environment that isn't .GlobalEnv with a large object that is unrelated to the model generation. It seems to save the irrelevant object unnecessarily. In my actual use case, I am running and saving many models in a

Re: [Rd] Model object, when generated in a function, saves entire environment when saved

2016-07-27 Thread William Dunlap via R-devel
One way around this problem is to make a new environment whose parent environment is .GlobalEnv and which contains only what the the call to lm() requires and to compute lm() in that environment. E.g., tfun1 <- function (subset) { junk <- 1:1e+06 env <- new.env(parent = globalenv())

[Rd] Model object, when generated in a function, saves entire environment when saved

2016-07-27 Thread Kenny Bell
In the below, I generate a model from an environment that isn't .GlobalEnv with a large object that is unrelated to the model generation. It seems to save the irrelevant object unnecessarily. In my actual use case, I am running and saving many models in a loop that each use a single large data.fram