[R] Save & reload list objects

Ista Zahn istazahn at gmail.com
Wed Aug 8 17:01:14 CEST 2012


Hi Rob,

On Wed, Aug 8, 2012 at 8:50 AM, robgriffin247 <rg.rforum at hotmail.co.uk> wrote:
> So it was simple, or so it seemed.
> Now to throw a spanner in the works!
>
> I got this error when testing it on my more powerful desktop (using one of
> my lists put in to a new object) :
>
> #put list in to new object called "temp"
> temp<-rg.lmer
> #save
> save(temp,file="C:\\Users\\...\\R & Data\\rg.lmer.txt")

It is conventional to save R workspace with ".Rdata" extension rather
than ".txt", although I don't think it actually makes a difference.

> #remove temp list from workspace to test load
> rm(temp)
> #load list in to a new object, again called temp.

> temp<-load("C:\\Users\\...\\R & Data\\rg.lmer.txt")

Don't assign the return value of load to an object(). Just do

load("C:\\Users\\...\\R & Data\\rg.lmer.txt")

>
>> temp<-load("C:\\Users\\...\\R & Data\\rg.lmer.txt")
> Error: cannot allocate vector of size 98 Kb
> In addition: Warning messages:
> 1: Reached total allocation of 8148Mb: see help(memory.size)
> 2: Reached total allocation of 8148Mb: see help(memory.size)
>
> The save process takes a very long time but works so I wonder if there is a
> quicker way to get the same result.
>
> The load takes a long time to throw out this error message. Again I hope
> there is a more efficient way to do it because it defeats the point of
> saving it in the first place if it takes as long as running the original
> script to make the list! Also it means I haven't been able to check if the
> load works and will produce the desired list.
>
>
> *Summary: Is there a better way than save / load, if not how can I get
> around this error message?*

Maybe, but I would start be trying again, starting from a clean R
session (either restart of run rm(list=ls()) to delete everything in
your workspace), and properly using load() as I illustrated above. If
you still have memory problems then you can start looking for another
solution.

Best,
Ista

> Rob
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Save-reload-list-objects-tp4639397p4639581.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.



More information about the R-help mailing list