【发布时间】:2019-07-06 23:17:11
【问题描述】:
我想在 Shell 脚本中运行 R 脚本,这对我来说不是问题:
例子:
#!/bin/bash
_input_file=$1
_output_file=$2
some shell script...
........
Rscript R.r >"_output_file" #call R script
我的问题是我想在我的 Shell 脚本中定义一个变量 (_output_file) 以分配给我的 R 脚本。 _output_file 包含输出的路径和文件夹名称。
R 脚本:
#!/usr/bin/env Rscript
x <- read.csv(_output_file,"/results/abc.txt", header=F)
library(plyr)
.....
.........
所以我希望调用变量 (_output_file) 及其路径能够读取 abc.txt 文件。 那么,如何在R脚本中引入Shell变量呢?
【问题讨论】:
-
这是一个非常常见的任务,有时被称为“R scipt 的命令行参数”或“Rscript 参数解析”。 StackOverflow 上有数百篇文章可供您学习。
标签: r linux shell parameter-passing