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

查看:15
本文介绍了使用传递文件的 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天全站免登陆