Skip to content

Change working directory

4 messages · anna, stephen sefick, Don MacQueen +1 more

#
.Rprofile is executed everytime you start up R
On Fri, Nov 13, 2009 at 8:34 AM, anna_l <lippelanna21 at hotmail.com> wrote:

  
    
#
In R for Macintosh, there is a Preferences setting that will do this.
You can also drag and drop a file onto the R icon and I believe it 
will change the working directory to the directory that contains the 
file.

On unix-like systems, using the command line, it's whatever directory 
you start R in.

I don't use R on Windows, so I don't know there, but I imagine there 
may be a preferences setting, or perhaps the drag and drop method 
works. Or maybe create a shortcut in the directory you want to be the 
working directory?

-Don
At 6:34 AM -0800 11/13/09, anna_l wrote:

  
    
#
anna_l wrote:

            
Hi Anna,
I create a .First function that is run when the session starts that looks like this:

.First<-function () {
  options(editor="nedit",show.signif.stars=FALSE)
  source("SelectAnalysis.R")
}

This runs the file "SelectAnalysis.R" that looks like this:

cat("(B)ullying\n(P)alatability\nR\n")
answer<-toupper(readline("Enter the letter corresponding to the project - "))
if(answer == "B") setwd("/home/jim/research/bullying/R")
if(answer == "P") setwd("/home/jim/research/palatability_heavydrink/R")
if(answer == "R") setwd("/home/jim/R")
print(list.files(pattern="[.]R"))

I can then select whatever analysis I happen to be working on with a single letter (and newline) and see all of the ".R" and ".Rdata" files in that directory.

Jim