Rscript 给脚本内传递参数

最直接的方式是args<-commandArgs(trailingOnly = TRUE)  ,对应args[1],args[2]

如:cat test.R  #脚本内容如下

args<-commandArgs(trailingOnly = TRUE)
print(args)
print (args[1])
print (args[2])

运行命令:

Rscript ./test.R WechatIMG326.jpeg WechatIMG957.jpeg

结果;

 

 注意:如果args<-commandArgs(trailingOnly = TRUE) ,就比较乱,如下

 

此外还有更近一步优美,适合推广使用的,但确实略繁琐的getopt以及optparse包 ,可以参考https://www.jianshu.com/p/8797972113d7。

 

posted on 2022-05-01 19:42  BioinformaticsMaster  阅读(223)  评论(0编辑  收藏  举报

导航