[R] Looking up the directory a file is located in

Cliff Clive cliffclive at gmail.com
Thu Nov 18 17:56:11 CET 2010

Thanks, Gabor!  So far I like this one best:

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)

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.

More information about the R-help mailing list