我正在 R 环境中包含多个子文件夹的文件夹中工作。我想要循环遍历多个子文件夹,然后在每个子文件夹中调用 R 脚本来执行。我想出了下面的代码。但我的代码似乎添加了“。”到子文件夹列表,我收到错误(“文件中的错误(文件名,“r”,编码=编码):
无效的“描述”参数”)。尽管调用 R 脚本没有问题。
code:
for (x in list.dirs()){
folder <- list.dirs(x)
script <- paste(folder,"/","process.R", sep="")
source(script)
}
这样做的正确方法是什么?我想我现在做的事情可能不对。
如果我理解正确的话,你有一个名为process.R
在多个子文件夹中。您想要运行所有这些脚本。如果是这种情况,我想以下方法会起作用:
folder <- list.dirs() # this assumes being in the main folder, otherwise specify the path
folder <- folder[-1] # comment this out if the main folder also contains the script
script.paths <- paste(folder,"/","process.R", sep="")
for (i in script.paths) {
source(i)
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)