Hi, When I create an environment object with new.env() and populate it with values then how can I save it into an .RData file properly, so it can be loaded later on in a new session? Saving an environment object with save() or save.image() results in an error message when loading again: Error: protect(): protection stack overflow Regards, benjamin =====================================Benjamin Otto University Hospital Hamburg-Eppendorf Institute For Clinical Chemistry Martinistr. 52 D-20246 Hamburg Tel.: +49 40 42803 1908 Fax.: +49 40 42803 4971 ===================================== -- Pflichtangaben gem?? Gesetz ?ber elektronische Handelsregister und Genossenschaftsregister sowie das Unternehmensregister (EHUG): Universit?tsklinikum Hamburg-Eppendorf K?rperschaft des ?ffentlichen Rechts Gerichtsstand: Hamburg Vorstandsmitglieder: Prof. Dr. J?rg F. Debatin (Vorsitzender) Dr. Alexander Kirstein Ricarda Klein Prof. Dr. Dr. Uwe Koch-Gromus
On Fri, 15 Aug 2008, Benjamin Otto wrote:> Hi, > > When I create an environment object with new.env() and populate it with > values then how can I save it into an .RData file properly, so it can be > loaded later on in a new session? > > Saving an environment object with save() or save.image() results in an error > message when loading again: > > Error: protect(): protection stack overflowsave/load works fine (and is used in many places):> e<-new.env() > assign("e", e, envir = e) > assign("x", 2, envir = e) > save(e, file = "test.Rda") > rm(e) > load("test.Rda") > e<environment: 0x1c2c748> There may be something about the values you are using that is causing problems, but there is no way to tell without a reproducible example. luke> > Regards, > > benjamin > > =====================================> Benjamin Otto > University Hospital Hamburg-Eppendorf > Institute For Clinical Chemistry > Martinistr. 52 > D-20246 Hamburg > > Tel.: +49 40 42803 1908 > Fax.: +49 40 42803 4971 > =====================================> > > >-- 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: luke at stat.uiowa.edu Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu
Benjamin Otto wrote:> Hi, > > When I create an environment object with new.env() and populate it with > values then how can I save it into an .RData file properly, so it can be > loaded later on in a new session? > > Saving an environment object with save() or save.image() results in an error > message when loading again: > > Error: protect(): protection stack overflowCan you give a small, reproducible example as the posting guide asks? And also provide your sessionInfo() ? I am not able to replicate this. test <- new.env() assign("hi", pi, pos = test) save(test, file = "~/testenv.Rdata") does not give me an error. Is this basically what you're trying?
Of course you said when you load it again. I just now loaded it, without error. FYI, my sessionInfo(), which I realize is not the latest version. sessionInfo() R version 2.7.0 (2008-04-22) i686-pc-linux-gnu locale: LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C attached base packages: [1] grDevices datasets grid tcltk splines graphics utils [8] stats methods base other attached packages: [1] fortunes_1.3-4 debug_1.1.0 mvbutils_1.1.1 erik_0.0-1 [5] reshape_0.8.0 SPLOTS_1.3-50 Hmisc_3.4-3 chron_2.3-21 [9] survival_2.34-1 loaded via a namespace (and not attached): [1] cluster_1.11.10 lattice_0.17-6 tools_2.7.0 Benjamin Otto wrote:> Hi, > > When I create an environment object with new.env() and populate it with > values then how can I save it into an .RData file properly, so it can be > loaded later on in a new session? > > Saving an environment object with save() or save.image() results in an error > message when loading again: > > Error: protect(): protection stack overflow > > Regards, > > benjamin > > =====================================> Benjamin Otto > University Hospital Hamburg-Eppendorf > Institute For Clinical Chemistry > Martinistr. 52 > D-20246 Hamburg > > Tel.: +49 40 42803 1908 > Fax.: +49 40 42803 4971 > =====================================> > > > > > ------------------------------------------------------------------------ > > ______________________________________________ > R-help at r-project.org 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.
Not so in general, so we need the details asked for in the posting guide, including a reproducible example. (Environments get saved all the time: they are a fundamental part of R's operations.) On Fri, 15 Aug 2008, Benjamin Otto wrote:> Hi, > > When I create an environment object with new.env() and populate it with > values then how can I save it into an .RData file properly, so it can be > loaded later on in a new session? > > Saving an environment object with save() or save.image() results in an error > message when loading again: > > Error: protect(): protection stack overflow > > Regards, > > benjamin > > =====================================> Benjamin Otto > University Hospital Hamburg-Eppendorf > Institute For Clinical Chemistry > Martinistr. 52 > D-20246 Hamburg > > Tel.: +49 40 42803 1908 > Fax.: +49 40 42803 4971 > =====================================-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Hi, can you please give a reproducible example and what's your sessionInfo()? Many years ago when I started to develop the Object class in R.oo, which is using environments, I also had problems saving environments directly. I my case I think it was when I added a class attribute to an environment, but I don't remember the details [theys are somewhere in the R-devel archives]. I never understood why it didn't work. What solved my problem was to put the environment as a element of something before save, e.g. in a list or as an attribute. So try this: env <- new.env(); ... x <- list(env=env); save("x", file="x.RData"); It might help /Henrik On Fri, Aug 15, 2008 at 4:41 AM, Benjamin Otto <b.otto at uke.uni-hamburg.de> wrote:> Hi, > > When I create an environment object with new.env() and populate it with > values then how can I save it into an .RData file properly, so it can be > loaded later on in a new session? > > Saving an environment object with save() or save.image() results in an error > message when loading again: > > Error: protect(): protection stack overflow > > Regards, > > benjamin > > =====================================> Benjamin Otto > University Hospital Hamburg-Eppendorf > Institute For Clinical Chemistry > Martinistr. 52 > D-20246 Hamburg > > Tel.: +49 40 42803 1908 > Fax.: +49 40 42803 4971 > =====================================> > > > -- > Pflichtangaben gem?? Gesetz ?ber elektronische Handelsregister und Genossenschaftsregister sowie das Unternehmensregister (EHUG): > > Universit?tsklinikum Hamburg-Eppendorf > K?rperschaft des ?ffentlichen Rechts > Gerichtsstand: Hamburg > > Vorstandsmitglieder: > Prof. Dr. J?rg F. Debatin (Vorsitzender) > Dr. Alexander Kirstein > Ricarda Klein > Prof. Dr. Dr. Uwe Koch-Gromus > > > ______________________________________________ > R-help at r-project.org 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. > >
On Fri, Aug 15, 2008 at 6:43 AM, Benjamin Otto <b.otto at uke.uni-hamburg.de> wrote:> Hi Erik, > > Yes this is what I was trying and your example or the one of luke is working > fine with me. > > So now I'm not sure if this is due to an environment which takes too much > space. The environment troubling me has 644276 entries. Is this too much?Use a divide-and-conquer approach and identify a minimal set of entries causing this problem. That will lead you to the right track. It certainly help to know what data types you have in your environment. /Henrik> > Benjamin > > -----Urspr?ngliche Nachricht----- > Von: Erik Iverson [mailto:iverson at biostat.wisc.edu] > Gesendet: Friday, August 15, 2008 3:37 PM > An: Benjamin Otto > Cc: R-Help > Betreff: Re: [R] Saving environment object > > Benjamin Otto wrote: >> Hi, >> >> When I create an environment object with new.env() and populate it with >> values then how can I save it into an .RData file properly, so it can be >> loaded later on in a new session? >> >> Saving an environment object with save() or save.image() results in an > error >> message when loading again: >> >> Error: protect(): protection stack overflow > > Can you give a small, reproducible example as the posting guide asks? > And also provide your sessionInfo() ? > > I am not able to replicate this. > > test <- new.env() > assign("hi", pi, pos = test) > save(test, file = "~/testenv.Rdata") > > does not give me an error. Is this basically what you're trying? > > > > > -- > Pflichtangaben gem?? Gesetz ?ber elektronische Handelsregister und Genossenschaftsregister sowie das Unternehmensregister (EHUG): > > Universit?tsklinikum Hamburg-Eppendorf > K?rperschaft des ?ffentlichen Rechts > Gerichtsstand: Hamburg > > Vorstandsmitglieder: > Prof. Dr. J?rg F. Debatin (Vorsitzender) > Dr. Alexander Kirstein > Ricarda Klein > Prof. Dr. Dr. Uwe Koch-Gromus > ______________________________________________ > R-help at r-project.org 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. >