使用传递文件的a.R在命令行上调用RMarkdown [英] call RMarkdown on command line using a.R that is passed a file

查看:168
本文介绍了使用传递文件的a.R在命令行上调用RMarkdown的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

总而言之,我正在RStudio的"input_file1.txt"上使用脚本"Graphs.R"创建一个Rmd,然后将其编织为html.我想自动执行此过程,以在命令行上运行更多文件.

In summary, I am using my script 'Graphs.R' on 'input_file1.txt' in RStudio to create a Rmd which I then knit to html. I would like to automate this process to run more files on the command line.

到目前为止,我可以使用以下命令使Rscript在命令行上运行:

So far, I can get the Rscript to run on the command line using:

Rscript Graphs.R input_file1.txt

Rscript Graphs.R input_file1.txt

我也知道我可以使用以下命令创建一个.RMD文件:

I also know that I can create an .RMD file using:

Rscript -e rmarkdown :: render(Graphs.R)

Rscript -e rmarkdown::render(Graphs.R)

但是,我想执行以下操作:

However, I would like to do the following:

Rscript -e rmarkdown :: render('Graphs.R input_file1.txt','output_file.Rmd')

Rscript -e rmarkdown::render('Graphs.R input_file1.txt', 'output_file.Rmd')

关于如何执行此操作有什么想法吗?

are there any ideas as how to do this?

推荐答案

目前尚不清楚您要做什么.似乎您有一个文本文件,必须通过R脚本将其转换为Rmd(为什么它不只是以Rmd开头?),然后要呈现Rmd.您可以通过在终端中运行以下命令来做到这一点:

It's not entirely clear what you are trying to do. It seems like you have a text file which has to be converted to an Rmd by an R script (why isn't it just an Rmd to begin with?) and then you want to render the Rmd. You can do this by running these commands in your terminal:

Rscript Graphs.R
Rscript -e "rmarkdown::render('output_file.Rmd')"

第一个命令运行Graphs.R文件,该文件可能会生成output_file.Rmd.第二个命令运行单线,将output_file.Rmd编织为output_file.html.

The first command runs the Graphs.R file which presumably generates output_file.Rmd. The second command runs a one-liner which knits output_file.Rmd into output_file.html.

如果要读取R文件中的命令行参数,请尝试?commandArgs.

If you want to read command line arguments in an R file, try ?commandArgs.

args <- commandArgs(trailingOnly = TRUE)

也请参见堆栈溢出问题.

这篇关于使用传递文件的a.R在命令行上调用RMarkdown的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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