search for: save_size_rds

Displaying 3 results from an estimated 3 matches for "save_size_rds".

Did you mean: save_size_qs
2020 Jan 29
2
Model object, when generated in a function, saves entire environment when saved
...thanks for any help and best wishes to all. The following code uses R 3.6.2 and requires you to run install.packages("qs") first: save_size_qs <- function (object) { tf <- tempfile(fileext = ".qs") on.exit(unlink(tf)) qs::qsave(object, file = tf) file.size(tf) } save_size_rds <- function (object) { tf <- tempfile(fileext = ".rds") on.exit(unlink(tf)) saveRDS(object, file = tf) file.size(tf) } normal_lm <- function(){ junk <- 1:1e+08 lm(Sepal.Length ~ Sepal.Width, data = iris) } normal_ggplot <- function(){ junk <- 1:1e+08 gg...
2020 Jan 29
0
Model object, when generated in a function, saves entire environment when saved
...ery useful test, because environments typically aren't filled with long sequence vectors. If you replace the line junk <- 1:1e+08 with junk <- runif(1e+08) you'll see drastically different results: > save_size_qs(normal_lm()) [1] 417953609 > #> [1] 848396 > save_size_rds(normal_lm()) [1] 532614827 > #> [1] 4163 > save_size_qs(normal_ggplot()) [1] 417967987 > #> [1] 857446 > save_size_rds(normal_ggplot()) [1] 532624477 > #> [1] 12895 Duncan Murdoch
2016 Jul 27
2
Model object, when generated in a function, saves entire environment when saved
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.Length ~ Sepal.Width, data=iris, subset=subset)$coef) } saveSize(tfun2(1:4)) #[1] 152 Bill