R指令行传递一个文件名脚本参数(视窗) [英] R command line passing a filename to script in arguments (Windows)

查看:1172
本文介绍了R指令行传递一个文件名脚本参数(视窗)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很难传递一个文件名到我的ř脚本。该文件与脚本的多次运行批处理参数csv文件。我想在这里包括它使得用户不需要为了指定文件的位置来编辑第r脚本

I'm having a hard time passing a filename to my R script. The file is a csv file with the batch parameters for multiple runs of the script. I am trying to include it here so that the user does not need to edit the R script in order to specify the location of that file.

我的Windows命令行语法是:

My Windows command line syntax is:

R CMD BATCH --slave "--args fn=batch.csv" myscript.r output.txt

我得到在我的 - [R脚本检索此最接近的是通过做:

The closest I have gotten to retrieving this in my R script is by doing:

eval(parse(file=commandArgs()[8])))
batch_args = read.table(fn, sep=",")

我与试验commandArgs(trailingOnly = TRUE)解析(文= commandArgs()[8])等,没有运气。大多数我所看到的并不专门通过文件名的申请文件。谁能想到一个解决方案?

I have experimented with commandArgs(trailingOnly=TRUE) and parse(text=commandArgs()[8]), etc., with no luck. Most of the documentation that I have seen does not apply specifically to passing filenames. Can anyone think of a solution?

推荐答案

正如我所说的在我的评论,我会使用 RSCRIPT 而不是研究CMD批

As I said in my comment, I would use Rscript instead of R CMD BATCH:

Rscript myscript.R batch.csv

在这里myscript.R包括:

where myscript.R contains:

args <- commandArgs(TRUE)
batch_args <- read.table(args[1], sep=",")
# loop over multiple runs

这篇关于R指令行传递一个文件名脚本参数(视窗)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆