Call RMarkdown on the command line using aR to which the file is transferred

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

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

Rscript Graphs.R input_file1.txt

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

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')

Any ideas how to do this?

+6
source share
1 answer

It is not clear what you are trying to do. It seems that you have a text file that needs to be converted to Rmd using an R script (why is it not just Rmd for starters?), And then you want to display Rmd. You can do this by running these commands in your terminal:

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

The first command runs the Graphs.R file, which supposedly creates output_file.Rmd . The second command launches a single-line, which inserts output_file.Rmd into output_file.html .

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

 args <- commandArgs(trailingOnly = TRUE) 

Also see this stack overflow question .

+10
source

Source: https://habr.com/ru/post/982463/


All Articles