繁体   English   中英

如何在R中将当前目录设置为其他目录?

[英]How can I set different directory to the current directory in R?

我正在尝试打开当前目录中不存在的文件。 该文件名为testFile.r存在于我当前目录的data文件夹中。 我尝试了file.path("./data") ,然后想要使用此命令file.show("testFile.r")显示文件,但是它给出了此错误:

错误:文件testFile.r不存在。

然后命令getwd()给出先前的当前目录。 那么对此有何想法?

您可以使用命令setwd(new_directory)更改当前目录(将new_directory替换为所需目录的路径)。

如果您希望保留在当前目录中,只需执行

file.show("./data/testFile.r")

要跟踪多个路径,可以将每个路径另存为变量,然后使用粘贴功能来引用文件:

path1 <- "./data/"
path2 <- "./second_folder_name/"
file.show(paste0(path1, "testFile.R"))
file.show(paste0(path2, "testFile.R"))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM