如何确定 R 中的当前目录名称? [英] How can I determine the current directory name in R?

查看:11
本文介绍了如何确定 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?)

推荐答案

您的示例代码对我不起作用,但您可能正在寻找 basenamedirname:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆