Hello [R]ians, I'm hoping someone can clarify the difference between a Workspace Image and Working Directory. I created a directory on my PC, say, "C:\Program Files\R\Project1" and then saved my objects in "C:\Program Files\R\Project1\.Rdata". Then, in a subsequent session, I reloaded these objects using> load("C:/Program Files/R/Project1/.RData")At first, I thought I was suppose to use> setwd("C:\\Program Files\\R\\Project1")and that R would automatically use "C:/Program Files/R/Project1/.RData". But this appears not to be the case. I got this impression from Section 1.11 of "An Introduction to R" which states "...objects are written to a file called '.RData' in the current directory". What "things" then, should go in the Workspace Image but not the Working Directory and vice versa (Plots?), and what am I not understanding? Gratefully Yours, Iyue ----------------------------------------- Iyue Sung, PhD Ingenix , Epidemiology Division -----------------------------------------
At 09:58 18/12/2002 -0500, vous avez ?crit:>Hello [R]ians, > > I'm hoping someone can clarify the difference between a Workspace Image >and Working Directory. I created a directory on my PC, say, >"C:\Program Files\R\Project1" and then saved my objects in >"C:\Program Files\R\Project1\.Rdata". > >Then, in a subsequent session, I reloaded these objects using > > > load("C:/Program Files/R/Project1/.RData") > >At first, I thought I was suppose to use > > > setwd("C:\\Program Files\\R\\Project1")This changes the working directory only for the current session.>and that R would automatically use "C:/Program Files/R/Project1/.RData". >But this appears not to be the case. >I got this impression from Section 1.11 of "An Introduction to R" which >states >"...objects are written to a file called '.RData' in the current directory". > >What "things" then, should go in the Workspace Image but not the Working >Directory >and vice versa (Plots?), and what am I not understanding?Under Windows, the most practical solution is to create a short-cut of Rgui.exe, right-click on it, and then modify the directory in the field "Start in:" under the tab "Short-cut". When started from this short-cut, R will use this directory as its working directory, and load any .RData if there is one there. You can then create as many short-cuts as you want, each with its own working directory. Hope this helps. Emmanuel Paradis>Gratefully Yours, > >Iyue > >----------------------------------------- >Iyue Sung, PhD >Ingenix , Epidemiology Division >----------------------------------------- > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >http://www.stat.math.ethz.ch/mailman/listinfo/r-help
On Wed, 18 Dec 2002, Iyue Sung wrote:> > Hello [R]ians, > > I'm hoping someone can clarify the difference between a Workspace Image > and Working Directory. I created a directory on my PC, say,The workspace image is a file (containing an R workspace), the working directory is a directory> "C:\Program Files\R\Project1" and then saved my objects in > "C:\Program Files\R\Project1\.Rdata".Good.> Then, in a subsequent session, I reloaded these objects using > > > load("C:/Program Files/R/Project1/.RData")Yes.> At first, I thought I was suppose to use > > > setwd("C:\\Program Files\\R\\Project1") > > and that R would automatically use "C:/Program Files/R/Project1/.RData". > But this appears not to be the case.No, because it's too late by then. At startup R automatically looks for .RData in the directory that it is started in, the initial working directory. Changing the working directory afterwards won't make a new .RData be loaded To change which workspace is loaded at startup you need to change the directory R starts in. The easiest way to do this under Windows is probably to make a number of different R shortcuts and set the 'Start in' directory in the Properties tab of each one.> I got this impression from Section 1.11 of "An Introduction to R" which states > "...objects are written to a file called '.RData' in the current directory".Yes. The current directory when the writing or reading is happening.> What "things" then, should go in the Workspace Image but not the Working Directory > and vice versa (Plots?), and what am I not understanding?R reads and writes everything in the current working directory unless told otherwise. I think you aren't understanding `current' -thomas
Thanks for the reply Thomas, I think I (am starting to) understand. But it appears that if I load, "C:\Program Files\R\Project1\.RData", after starting in the directory "C:\Program Files\R\rw1060", R will save the objects I create in the current session in both "C:~\Project1" and "C:~\rw1060". So, if all I really care about is making sure objects for projects are stored in different .RData files, why would it matter which directory I start in? Thanks, Iyue> -----Original Message----- > From: Thomas Lumley [mailto:tlumley at u.washington.edu] > Sent: Wednesday, December 18, 2002 11:05 AM > To: Iyue Sung > Cc: R-help at stat.math.ethz.ch > Subject: Re: [R] workspace vs. image > > > On Wed, 18 Dec 2002, Iyue Sung wrote: > > > > > Hello [R]ians, > > > > I'm hoping someone can clarify the difference between a > Workspace Image > > and Working Directory. I created a directory on my PC, say, > > The workspace image is a file (containing an R workspace), the working > directory is a directory > > > "C:\Program Files\R\Project1" and then saved my objects in > > "C:\Program Files\R\Project1\.Rdata". > > Good. > > > Then, in a subsequent session, I reloaded these objects using > > > > > load("C:/Program Files/R/Project1/.RData") > > Yes. > > > At first, I thought I was suppose to use > > > > > setwd("C:\\Program Files\\R\\Project1") > > > > and that R would automatically use "C:/Program > Files/R/Project1/.RData". > > But this appears not to be the case. > > No, because it's too late by then. > > At startup R automatically looks for .RData in the directory > that it is > started in, the initial working directory. Changing the > working directory > afterwards won't make a new .RData be loaded > > To change which workspace is loaded at startup you need to change the > directory R starts in. The easiest way to do this under Windows is > probably to make a number of different R shortcuts and set > the 'Start in' > directory in the Properties tab of each one. > > > I got this impression from Section 1.11 of "An Introduction > to R" which states > > "...objects are written to a file called '.RData' in the > current directory". > > Yes. The current directory when the writing or reading is happening. > > > What "things" then, should go in the Workspace Image but > not the Working Directory > > and vice versa (Plots?), and what am I not understanding? > > R reads and writes everything in the current working > directory unless told > otherwise. I think you aren't understanding `current' > > > -thomas > > >