Hi R users, I am still a relatively new R user migrated from S+. I wonder in R how do you handle one difference between R and S+. S+ saves objects as different files in .Data directory while R saves all objects in a big file .RData. In S+, I can start two S+ sessions from the same directory and work simultaneously as long as new objects in the two sessions are not in the same names. This is particularly useful in simulation studies. However, this method fails for R. I am curious how other R users handle this thing in R. Naively, I can copy .Rdata into another directory and then start another R session there. When the job is done, dump all new objects in one .Rdata into the other .Rdata. But maybe someone has a better way to do it. BTW, why does R save objects in one big file rather than as different files in a directory as S+ does? Thanks. Paul. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>>>>> "PaulYP" == Paul Y Peng <ypeng at math.mun.ca> writes:PaulYP> Hi R users, I am still a relatively new R user PaulYP> migrated from S+. I wonder in R how do you handle PaulYP> one difference between R and S+. S+ saves objects as PaulYP> different files in .Data directory while R saves all PaulYP> objects in a big file .RData. In S+, I can start two PaulYP> S+ sessions from the same directory and work PaulYP> simultaneously as long as new objects in the two PaulYP> sessions are not in the same names. This is PaulYP> particularly useful in simulation studies. However, PaulYP> this method fails for R. I am curious how other R PaulYP> users handle this thing in R. Naively, I can copy PaulYP> .Rdata into another directory and then start another PaulYP> R session there. When the job is done, dump all new PaulYP> objects in one .Rdata into the other .Rdata. But PaulYP> maybe someone has a better way to do it. I never work with .RData at all. I believe in the virtue of ``reproducible'' research and data analysis and hence almost exclusively work with "scripts", where I define functions, and call functions defining other objects. In most cases, I rerun my scripts which may call other scripts via source(.). Only rarely (but always when doing simulations), I *do* save specific objects explicitely, but then I use different file names than .RData, e.g. after some expensive simulations, I might have save(list= c("x","K0","Kset","n","nK","B", "vK0", "n.matches", "rr"), file= file.path(PROJDIR,"EB1k-bootstrap-r2-4.rda")) where PROJDIR is a character variable containing the project directory. Then, to start from these results, I explicitely do load(file.path(PROJDIR,"EB1k-bootstrap-r2-4.rda")) which will restore the "x", "K0", ... objects but only those. PaulYP> BTW, why does R save objects in one big file rather PaulYP> than as different files in a directory as S+ does? Originally, S and S+ save objects in files ``all the time'' (this is an oversimplification nowadays; in early versions of S it was true) whereas R does not save anything in files unless told so. Saving everything in .RData is only upon (direct or indirect) user request! Look at help(save.image) help(q) help(save) Martin Maechler <maechler at stat.math.ethz.ch> http://stat.ethz.ch/~maechler/ Seminar fuer Statistik, ETH-Zentrum LEO C16 Leonhardstr. 27 ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND phone: x-41-1-632-3408 fax: ...-1228 <>< -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Mon, 1 Apr 2002, Paul Y. Peng wrote:> Hi R users, > > I am still a relatively new R user migrated from S+. I wonder in R > how do you handle one difference between R and S+. S+ saves objects > as different files in .Data directory while R saves all objects in > a big file .RData. In S+, I can start two S+ sessions from the same > directory and work simultaneously as long as new objects in the two > sessions are not in the same names. This is particularly useful in > simulation studies. However, this method fails for R. I am curious > how other R users handle this thing in R. Naively, I can copy .Rdata > into another directory and then start another R session there. When > the job is done, dump all new objects in one .Rdata into the other > .Rdata. But maybe someone has a better way to do it.You can save the workspace to a file with a different name using the save.image() function. That way you could have oneproject.rdata, and anotherproject.rdata holding the two sets of data. You could also have a third file with objects you wanted to use in more than one project, say commonobjects.rdata. You might then do R> load("oneproject.rdata") R> attach("commonobjects.rdata") R> work, work, work R> save.image("oneproject.rdata") R> q("no") so that the common objects aren't saved into "oneproject.rdata" but the rest of your work is.> BTW, why does R save objects in one big file rather than as different > files in a directory as S+ does? >Partly because it's harder to separate objects in R. The fact that functions and model formulas have attached environments means that you may have to keep quite large collections of objects together in an R file. I actually think it's easier to keep track of things the R way -- you decide when things go in the same file, whereas with S-PLUS it depends on what your working directory happens to be. This might just indicate successful brainwashing, though. -thomas Thomas Lumley Asst. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Many thanks to Jason Turner, Martin Maechler and Thomas Lumley. They all pointed to save.image(), which is really what I am after. Sorry for my ignorant. Before I posted my question, I did checked the help page of q() and the manual "An Introduction to R", "R Language Definition" etc. Unfortunately none of them mentions save.image(). However, I am glad that my intuition is right and that R has a nice way to manage objects. Thanks for help. Paul. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Paul Y. Peng <ypeng at math.mun.ca> wrote:> I wonder in R how do you handle one difference between R and S+. S+ saves > objects as different files in .Data directory while R saves all objects in > a big file .RData.In both S+ and R, I treat objects in the workspace (pos=1) as disposable, and objects in attached databases (pos>1) as permanent. I wrote the R package "g.data" to store these permanent objects in separate files as S+ does: <http://cran.r-project.org/src/contrib/g.data_1.2.tar.gz> "g.data" only loads the objects you actually use, so you don't have to read a huge .RData file if you only want a small subset of the data. Give it a try!> ..I can start two S+ sessions from the same directory and work simultaneously > as long as new objects in the two sessions are not in the same names.This strikes me as dangerous, especially since I have so many "x" and "y" variables all over. Multiple sessions in R are much nicer, since I never store my workspace and so there is never any interference. No need to worry about what working directory I started R up in. -- -- David Brahm (brahm at alum.mit.edu) -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._