Rscript 传参数,非常简单的方法
例子如下 :
args = commandArgs(trailingOnly=TRUE)
if (length(args)!=6) {
stop("Rscript 1_compare_results.R file1 file2 outdir outname file3 file4")
} else if (length(args)==6) {
print(paste("input1:",args[1],";input2,",args[2],",outdir:",args[3],",outname:",args[4],"input3:",args[5],"input4:",args[6],sep = ""))
}
test脚本有6个参数,
如果不是6个参数,就停止程序 , 打印出相应的用法
如果是6个就print出这些参数,往下运行
Rscript test.R
这里的vanilla是 不保存工作空间,不输出不必要的屏幕显示等等,不加也可以运行
ref:
https://www.r-bloggers.com/passing-arguments-to-an-r-script-from-command-lines/