-------- Original-Nachricht -------- > Datum: Thu, 08 Mar 2012 09:51:01 -0500 > Von: Duncan Murdoch <murdoch.dun...@gmail.com> > An: "R. Michael Weylandt" <michael.weyla...@gmail.com> > CC: Johannes Radinger <jradin...@gmx.at>, R-help@r-project.org > Betreff: Re: [R] Save/Load function()-result to file in a loop
> On 08/03/2012 8:42 AM, R. Michael Weylandt wrote: > > Load doesn't return the object you saved, but rather a character > > vector with the name of that object, here "x". So you would do > > something like > > > > load("/path/to/file_A") > > x # Here's your data > > > > or more robustly > > > > get(load("/path/to/file_A")) > > > > See ?load (value) for details. > > I think that's a bad idea: it still wipes out any existing x in the > workspace. Use saveRDS() and readRDS() instead. For example, > > # Save the object, not its name > i <- "A" > saveRDS(x, file ="/path/to/file_A") > > # Load it into a new name > A <- loadRDS("/path/to/file_A") Hi Duncan, Thank for that good tip to use the RDS-functions. Anyway I think you meant readRDS() instead of loadRDS(). I tried it out and it is working as I want it :) /johannes > > Duncan Murdoch > > > Michael > > > > On Thu, Mar 8, 2012 at 7:57 AM, Johannes Radinger<jradin...@gmx.at> > wrote: > > > Hi, > > > > > > I am looking for a way to save the result of a function, e.g the > lm()-function to a file and reload it afterwards again. I'd like to do that in > order to minimize the used memory when running the function in a loop. The > actual function I want to store is the evaluate() from the dismo package. > > > I tried it with save() and load() but I am not sure if that is the > way I should do it as I don't get the result I desire... > > > > > > ls<- list("A","B","C") > > > for(i in ls){ > > > x<- lm(c(1,2,3)~c(2,5,6)) > > > save(x, file = paste("/path/to/file_",i,sep="")) > > > } > > > > > > A<- load("/path/to/file_A") > > > > > > /Johannes > > > -- > > > > > > Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a > > > > > > ______________________________________________ > > > R-help@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. > > > > ______________________________________________ > > R-help@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. > -- Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a ______________________________________________ R-help@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.