R语言中实现在命令行中传参

 

001、

复制代码
root@PC1:/home/test3# cat a.txt
1
2
3
4
5
root@PC1:/home/test3# cat b.txt
test01
test02
test03
test04
test05
root@PC1:/home/test3# cat test.r

library(optparse)

option_list <- list(make_option("--file1", type = "character", default = NULL, help = "xxxx"), make_option("--file2", type = "character", default = NULL, help = "yyy"))

opt <- parse_args(OptionParser(option_list = option_list))

dat1 <- read.table(opt$file1)
dat2 <- read.table(opt$file2)

dat <- rbind(dat1[1:3,], dat2[1:3,])

write.table(dat, "new.txt", row.names = F, col.names = F, quote = F)
复制代码

 

 

 

 

 

002、

root@PC1:/home/test3# ls
a.txt  b.txt  test.r
root@PC1:/home/test3# Rscript test.r --file1 a.txt --file2 b.txt
root@PC1:/home/test3# ls
a.txt  b.txt  new.txt  test.r
root@PC1:/home/test3# cat new.txt
1 2 3
test01 test02 test03

 

posted @   小鲨鱼2018  阅读(115)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2021-06-22 c语言中以10进制、8进制、16进制显示同一个数字
点击右上角即可分享
微信分享提示