Hello, I am using setwd() to change the working directory but I have to enter it everytime I open R, is there a way to set this permanently as a working directory? Thanx =^D -- View this message in context: http://old.nabble.com/Change-working-directory-tp26337486p26337486.html Sent from the R help mailing list archive at Nabble.com.
.Rprofile is executed everytime you start up R On Fri, Nov 13, 2009 at 8:34 AM, anna_l <lippelanna21 at hotmail.com> wrote:> > Hello, I am using setwd() to change the working directory but I have to enter > it everytime I open R, is there a way to set this permanently as a working > directory? Thanx =^D > > -- > View this message in context: http://old.nabble.com/Change-working-directory-tp26337486p26337486.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Stephen Sefick Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis
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:>Hello, I am using setwd() to change the working directory but I have to enter >it everytime I open R, is there a way to set this permanently as a working >directory? Thanx =^D > >-- >View this message in context: >http://*old.nabble.com/Change-working-directory-tp26337486p26337486.html >Sent from the R help mailing list archive at Nabble.com. > >______________________________________________ >R-help at r-project.org mailing list >https://*stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide http://*www.*R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.-- -------------------------------------- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA 925-423-1062
anna_l wrote:> Hello, I am using setwd() to change the working directory but I have to enter > it everytime I open R, is there a way to set this permanently as a working > directory? Thanx =^D >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
On Fri, Nov 13, 2009 at 6:24 PM, Don MacQueen <macq at llnl.gov> 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?On Windows if you start R using Rgui.bat from the command line then it will start in whatever directory you were in (as in UNIX). Rgui.bat is a single file with no dependencies so just copy it to any directory on your path. It will automatically find R using the registry and then start it up. Rgui.bat is found in the batchfiles distribution whose home page is: http://batchfiles.googlecode.com