如何将向量作为命令行变量传递?

时间:2018-04-01 15:36:37

标签: r

我有一个名为script.r的R脚本:

someVector <- theCommandLineArgument

如何通过命令行R将c("some","vector")传递给theCommandLineArgument

1 个答案:

答案 0 :(得分:0)

script.r的内容:

input <- commandArgs(trailingOnly = TRUE)

print (paste("Sum of arguments = ", sum(as.numeric(input[1:3]))))
print(input[4:5])

终端:

Rscript script.R 1 2 3 Hello World

输出:

[1] "Sum of arguments =  6"
[1] "Hello" "World"