[R] Two R sessions?

Martin Maechler maechler at stat.math.ethz.ch
Tue Apr 2 10:48:58 CEST 2002


>>>>> "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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list