R: Using R with project directories under Windows

From MathWiki

It is very desirable to use different directories for different projects in R. There are many ways of doing this. The following is one way that is reasonably simple. It is based on the fact that R can be started by clicking on a workspace (.Rdata) file and the 'working directory' will be the directory in which the .Rdata file was clicked. Thus to use a directory as a project directory you need only copy a .Rdata file to that directory. After installing R, you can start R and save the workspace in a convenient place such as the Desktop using "File|Save Workspace".

To set up a project directory, you can do the following:

  1. create the directory
  2. copy .Rdata into the directory
  3. create at least two sub-directories of your directory: 'R' and 'data'
  4. start R by clicking on .Rdata
  5. save scripts in the 'R' subdirectory
  6. save important data frames in the 'data' sub-directory with, e.g. save( dd, file = 'data/dd.rda')

If you want to reload the data frame 'dd' in a later session, you merely type the command

 > data(dd)

All file references are relative to the project directory. To display the project directory from the R session, use:

 > getwd()