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?)
Your example code doesn't work for me, but you're probably looking for either
basename
ordirname
:If you didn't know
basename
(and I didn't), you could have used this: