R脚本中使用命令行 进行传参
1、
root@PC1:/home/test# cat test.r library(optparse) option_list <- list( make_option(c("-p", "--arg1"), type = "character", default=FALSE), make_option(c("-q", "--arg2"), type = "character", default=FALSE), make_option(c("-m", "--arg3"), type = "character", default=FALSE) ) opt_parser = OptionParser(option_list=option_list); opt = parse_args(opt_parser); file1 = read.table(opt$arg1,header = F) file2 = read.table(opt$arg2,header = F) file3 = read.table(opt$arg3,header = F) file4 = rbind(file3, file2, file1) write.table(file4, "x.csv", row.names = F, col.names = F, sep = "\t")
root@PC1:/home/test# cat a.txt 1 1 1 1 1 1 root@PC1:/home/test# cat b.txt 2 2 2 2 2 2 root@PC1:/home/test# cat c.txt 3 3 3 3 3 3
2、测试运行
root@PC1:/home/test# Rscript test.r --arg1 a.txt --arg2 b.txt --arg3 c.txt root@PC1:/home/test# ls a.txt b.txt c.txt test.r x.csv root@PC1:/home/test# cat x.csv 3 3 3 3 3 3 2 2 2 2 2 2 1 1 1 1 1 1
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
2020-10-23 linux系统中du命令
2020-10-23 linux系统中fdisk命令进行磁盘分区
2020-10-23 linux系统中挂载mount命令、umount命令