[R] features of save and save.image (unexpected file sizes)
Vaidotas Zemlys
mpiktas at gmail.com
Thu Feb 1 14:30:14 CET 2007
Hi,
On 2/1/07, Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:
> On Thu, 1 Feb 2007, Vaidotas Zemlys wrote:
>
> > Hi,
> >
> > On 1/31/07, Professor Brian Ripley <ripley at stats.ox.ac.uk> wrote:
> >> Two comments:
> >>
> >> 1) ls() does not list all the objects: it has all.names argument.
> >>
> > Yes, I tried it with all.names, but the effect was the same, I forgot
> > to mention it in a letter.
> >
> >> 2) save.image() does not just save the objects in the workspace, it also
> >> saves any environments they may have. Having a function with a
> >> large environment is the usual cause of a large saved image.
> >
> > I have little experience dealing with enivronments, so is there a
> > quick way to discard the environments of the functions? When saving
> > the session I really do not need them.
>
> Change, not discard. E.g. environment(f) <- .GlobalEnv. If environments
> are not mentioned by anything saved, they will not be saved.
>
I found the culprit. I was parsing formulas in my code, and I saved
them in that large object. So the environment came with saved
formulas. Is there a nice way to say R: "please do not save the
environments with the formulas, I do not need them?"
This is what I was doing (I am discarding irrelevant code)
testf<- function(formula) {
mainform <- formula
if(deparse(mainform[[3]][[1]])!="|") pandterm("invalid conditioning
for main regression")
mmodel <- substitute(y~x,list(y=mainform[[2]],x=mainform[[3]][[2]]))
mmodel <- as.formula(mmodel)
list(formula=list(main=mmodel))
}
when called
bu <- testf(lnp~I(CE/12000)+hhs|Country)
I get
ls(env=environment(bu$formula$main))
[1] "formula" "mainform" "mmodel"
or in actual case, a lot of more objects, which I do not need, but
which take a lot of place. For the moment I solved the problem with
environment(mmodel) <- NULL
but is this correct R way?
Vaidotas Zemlys
--
Doctorate student, http://www.mif.vu.lt/katedros/eka/katedra/zemlys.php
Vilnius University
More information about the R-help
mailing list