Saving a single object within a function in R: RData file size is very large

前端 未结 2 652
小鲜肉
小鲜肉 2021-02-10 01:10

I am trying to save trimmed-down GLM objects in R (i.e. with all the \"non-essential\" characteristics set to NULL e.g. residuals, prior.weights, qr$qr).

As an example,

2条回答
  •  無奈伤痛
    2021-02-10 01:41

    Do you find that you have the same problem when you name the arguments in your call to save?

    I used:

    subFn <- function(y, x){
                 glmObject <- glm(y ~ x, family = "binomial")
                 save(list = "glmObject", file = "FileName.RData")
    }
    
    mainFn <- function(y, x){ 
             subFn(y, x)
    }
    
    mainFn(y = rbinom(n = 10, size = 1, prob = 1 / 2), x = 1:10)
    

    I saw that the file "FileName.RData" was created in my working directory. It is 6.6 kb in size.

    I then use:

    load("FileName.RData")
    

    to load the contents, glmObject, to my global environment.

提交回复
热议问题