Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I determine the current directory name in R?

Tags:

The only solution I've encountered is to use regular expressions and recursively replace the first directory until you get a word with no slashes.

gsub("/\\w*/","/",gsub("/\\w*/","/",getwd()))

Is there anything slightly more elegant? (and more portable?)

like image 245
M. Tibbits Avatar asked Apr 26 '11 21:04

M. Tibbits


1 Answers

Your example code doesn't work for me, but you're probably looking for either basename or dirname:

> getwd()
[1] "C:/cvswork/data"
> basename(getwd())
[1] "data"
> dirname(getwd())
[1] "C:/cvswork"
like image 131
Joshua Ulrich Avatar answered Oct 01 '22 02:10

Joshua Ulrich