如何在R中确定当前目录名称? [英] How can I determine the current directory name in R?
本文介绍了如何在R中确定当前目录名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到的唯一解决方案是使用正则表达式并递归替换第一个目录,直到找到一个没有斜杠的单词。
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?)
推荐答案
您的示例代码不适用于我, code> basename 或 dirname
:
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"
这篇关于如何在R中确定当前目录名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文