【发布时间】:2015-06-20 00:33:55
【问题描述】:
我想使用Rscript 执行脚本file.R。在file.R,我使用包dplyr。
# file.R
df <- data.frame(ID,x,y,z,...)
library(dplyr)
filter(df, ID != "null")
......
如果我没有在批处理文件中指定任何选项,则一切正常,因为 file.R 包括行 library(dplyr)
# 1) no specification of packages in the batch file
Rscript.exe file.R arg1 arg2 arg3 > outputFile.Rout 2>&1
但是,如果我在批处理文件中添加default-packages=utils,
# 2) specification of packages utils in the batch file
Rscript.exe default-packages=utils file.R arg1 arg2 arg3 > outputFile.Rout 2>&1
使用dplyr的file.R部分不再起作用(Error in filter(df, ID != 'null') : Object 'ID' could not be found)
因为?Rscript 说
--default-packages=list
where list is a comma-separated list of package names or NULL
我尝试添加--default-packages=utils,dplyr,
# 3) specification of packages utils and dplyr in the batch file
Rscript.exe default-packages=utils,dplyr file.R arg1 arg2 arg3 > outputFile.Rout 2>&1
导致与2中相同的错误
为什么批处理文件1 是唯一有效的?我在所有 3 个备选方案中都调用了相同的 R 脚本。
【问题讨论】:
-
您是否觉得有必要在命令行中指定软件包,而不是仅仅将各自的
library放在脚本的开头? -
问题是,将
library放在脚本的开头不是解决方案,这就是我发帖的原因。在所有 3 个备选方案中,我调用了相同的脚本file.R,它在开始时包含库命令。 -
我以为您说选项 1 在您未指定任何选项的情况下有效?我误解你的说法了吗?你的问题不是很清楚。
-
编辑后是否更清晰了?如果没有,你能具体说明什么不清楚吗?无论如何感谢您的反馈。
-
@Dason 不,我以前试过。我还读到过去链接运算符和 Rscript 存在问题,但即使删除链接运算符也无法正常工作。
标签: r batch-file rscript