[R] Saving environment object

Luke Tierney luke at stat.uiowa.edu
Fri Aug 15 18:29:12 CEST 2008


On Fri, 15 Aug 2008, Prof Brian Ripley wrote:

> Having been told that this was a particular very large environment, Luke's 
> comments in serialize.c wouild seem to apply:
>
>   The output format for dotted pairs writes the ATTRIB value first
>   rather than last.  This allows CDR's to be processed by iterative
>   tail calls to avoid recursion stack overflows when processing long
>   lists.  The writing code does take advantage of this, but the
>   reading code does not.  It hasn't been a big issue so far--the only
>   case where it has come up is in saving a large unhashed environment
>   where saving succeeds but loading fails because the PROTECT stack
>   overflows.  With the ability to create hashed environments at the
>   user level this is likely to be even less of an issue now.  But if
>   we do need to deal with it we can do so without a change in the
>   serialization format--just rewrite ReadItem to pass the place to
>   store the CDR it reads. (It's a bit of a pain to do, that is why it
>   is being deferred until it is clearly needed.)

Thanks -- I had forgotten about that (and would still prefer to defer
rewriting ReadItem :-))

luke

> So I think the moral is to hash large environments, and increasing 
> --max-ppsize should enable this one to be read in.
>
> On Fri, 15 Aug 2008, Luke Tierney wrote:
>
>> 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
>> 
>> save/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
>> 
>> ______________________________________________
>> 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.
>> 
>
>

-- 
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



More information about the R-help mailing list