[R] saving and loading complex objects

Gabor Grothendieck ggrothendieck at gmail.com
Mon Oct 1 20:27:59 CEST 2007


formulas have environments and since most model structures
include the formula the entire environment of the formula will be pulled in.


On 10/1/07, hadley wickham <h.wickham at gmail.com> wrote:
> Why are you using eval and not:
>
> path <- paste( "C://Program Files//R//R-2.5.1//arima//",nn, sep="")
> save(x, file = path)
>
> ?
>
> It's possible that extra environments are getting saved.  (Someone
> with more knowledge of eval might suggest a better solution, but that
> might be a good place to start)
>
> Hadley
>
> >
> > pp=paste( "save(  x, file=", sQuote(pp),")", sep="" )
> > eval(parse(text=pp))
>
>
> On 10/1/07, Lloyd Lubet <lloyd.lubet at gmail.com> wrote:
> > Dear Sir:
> >
> > When I try to save large and very complex recursive objects with some components containing models (such as the output from arima or lm ),
> > the resulting file sizes increase by 4 meg per save.
> >
> > example directory:
> >
> > amex                8 meg
> > argentina         12 meg
> > australia          16 meg
> > ...
> >
> > Moreover, I am unable to read these file objects back into R.
> > I note that readBin and writeBin are only for single mode data such as numeric.
> >
> > Here is a section of my program or script:
> >
> > SaveObj = function( x, nn ) {
> >
> > pp=paste( "C://Program Files//R//R-2.5.1//arima//",nn, sep="")
> >
> > pp=paste( "save(  x, file=", sQuote(pp),")", sep="" )
> > eval(parse(text=pp))
> > }       # end of function: SaveObj
> > load( file="C://Program Files//R//R-2.5.1//arima//amex" )
> >
> >
> >
> >
> > allArima=function( yy, popSize=10, generations=5 ){
> >
> > nn = names(yy)
> > for( i in 1:dim(yy)[2] ) {
> >
> > print( paste( "    iter: ", i, "name: ", " ", names(yy)[i],sep="")  )
> >
> > #                                                 data                 AVY              Note lagxy <- CreateColumnSpace( yy, column = i, startLag = 1, endLag = 8, exclude=T, by=1 )
> >
> > xx <- xy$xx
> >
> > response = xy$response
> >
> > t.index = xy$indx
> >
> >
> >
> >
> > # genetically select predictor column space
> >
> > result = intGa( response =response, ... ,
> >
> >                        FUN = LM, monitor = F, monitorFun = nn.Monitor,
> >
> >                        Evaluator = Std.Eval, wildCardPct = 0.10,
> >
> >                         parm1 = 4, parm2 = 1, parm3 = 3 )
> >
> > x.model=result$bestModel
> >
> > SaveObj( x=x.model, nn=nn[i] )
> >
> > rm(result,x.model)
> >
> > }       # end for
> >
> >
> > return( formulaLst )
> >
> > }               # end of allArimaVery Sincerely,Lloyd Lubet
> >
> >         [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > 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.
> >
>
>
> --
> http://had.co.nz/
>
> ______________________________________________
> 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