Thanks, Gabor! So far I like this one best: https://stat.ethz.ch/pipermail/r-help/2005-November/082347.html
So if my script is called "myRscript.r", I can do the following: this.file = parent.frame(2)$ofile this.dir = gsub("/myRscript.r", "", this.file) setwd(this.dir) This will set the working directory to the the directory that myRscript.r lives in, no matter where I move the script. It's nice that it can be done in only three lines of code, although it's not yet a perfect solution, since it won't work if I change the name of the script. But that's easy to take care of if I just do some slightly more sophisticated string manipulation (which I'm terrible at doing off the top of my head). -- View this message in context: http://r.789695.n4.nabble.com/Looking-up-the-directory-a-file-is-located-in-tp3047649p3049113.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@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.