我有一个 R 脚本,我想将一些文件名/参数传递给我的 Rscript 并从终端执行它。我使用了这个命令:
fileA='aaaa.txt'
fileB='bbbb.txt'
n=100
string='hello'
R CMD BATCH --vanilla '--args $fileA $fileB $n $string' Rscript_file.R
我在我的 Rscript_file.R 文件中添加了这一行:
args <- commandArgs(trailingonly=TRUE)
但我收到了这个错误:
> args <- commandArgs(trailingonly=TRUE)
Error in commandArgs(trailingonly = TRUE) :
unused argument (trailingonly = TRUE)
Execution halted
有任何想法吗?谢谢