On Fri, 2 Feb 2007, Prof Brian Ripley wrote: > On Fri, 2 Feb 2007, Vaidotas Zemlys wrote: > >> Hi, >> >> On 2/2/07, Prof Brian Ripley <[EMAIL PROTECTED]> wrote: >> >>>> 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?" >>> >>> No, but why create them that way? You could do >>> >>> mmodel <- as.formula(mmodel, env=.GlobalEnv) >>> >> Hm, but say I have some large object in .GlobalEnv, and I generate >> mmodel 10 different times and save the result as a list with length >> 10. Now if I try to save this list, R will save 10 different copies of >> .GlobalEnv together with aforementioned large object? > > No, it saves the environment (here .GlobalEnv), not objects, and there can > be many shared references.
Just to amplify this point: Only a marker representing .GlobalEnv is saved; on load into a new session that marker becomes the .GlobalEnv of the new session. Best, luke > >>> The R way is to create what you want, not fix up afterwards. >>> >>> (I find your code unreadable--spaces help a great deal, so am not sure if >>> I have understood it correctly.) >>> >> Hm, I copied this code directly from Emacs+ESS, maybe the mailer >> mangled something. What I want to do with this piece of code (I will >> repaste it here) >> >> testf<- function(formula) { >> mainform <- formula >> if(deparse(mainform[[3]][[1]])!="|") stop("invalid conditioning") >> mmodel <- substitute(y~x,list(y=mainform[[2]],x=mainform[[3]][[2]])) >> mmodel <- as.formula(mmodel) >> list(formula=list(main=mmodel)) >> } > > You use no spaces around your operators or after commas. R does when > deparsing: > >> testf > function (formula) > { > mainform <- formula > if (deparse(mainform[[3]][[1]]) != "|") > stop("invalid conditioning") > mmodel <- substitute(y ~ x, list(y = mainform[[2]], x = > mainform[[3]][[2]])) > mmodel <- as.formula(mmodel) > list(formula = list(main = mmodel)) > } > > because it is (at least to old hands) much easier to read. > > IcanreadEnglishtextwithoutanyspacesbutIchoosenotto.Similarly,Rcode.Occasional > spacesare evenharderto parse. > >> is to read formula with condition: >> >> formula(y~x|z) >> >> and construct formula >> >> formula(y~x) >> >> I looked for examples in code of coplot in library graphics and >> latticeParseFormula in library lattice. >> >> Vaidotas Zemlys >> -- >> Doctorate student, http://www.mif.vu.lt/katedros/eka/katedra/zemlys.php >> Vilnius University >> > > -- Luke Tierney Chair, Statistics and Actuarial Science Ralph E. Wareham Professor of Mathematical Sciences University of Iowa Phone: 319-335-3386 Department of Statistics and Fax: 319-335-3017 Actuarial Science 241 Schaeffer Hall email: [EMAIL PROTECTED] Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.