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, looking at the smallest object that I need to do this with:
print(object.size(glmObject))
168992 bytes
save(glmObject, "FileName.RData")
Assigning this object in the global environment and saving leads to an RData file of about 6KB.
However, I effectively need to create and save the glm object within a function, which is in itself within a function. So the code looks something like:
subFn <- function(DT, otherArg, ...){
glmObject <- glm(...)
save(glmObject,"FileName.RData")
}
mainFn <- function(DT, ...){
subFn(DT, otherArg, ...)
}
mainFn(DT, ...)
Which leads to much, much larger RData files of about 20 MB, despite the object itself being the same size.
So I understand this to be an environment issue, but I'm struggling to pinpoint exactly how and why it's happening. The resulting file size seems to vary quite a lot. I have tried using saveRDS, and equally I have tried assigning the glmObject via <<- to make it global, but nothing seems to help.
My understanding of environments in R clearly isn't very good, and would really appreciate if anyone could suggest a way around this. Thanks.
object.size
from within the function? – Impersonalize