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