call RMarkdown on command line using a.R that is passed a file

前端 未结 1 802
情歌与酒
情歌与酒 2020-12-31 04:04

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

相关标签:
1条回答
  • 2020-12-31 05:04

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

    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.

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

    args <- commandArgs(trailingOnly = TRUE)
    

    Also see this Stack Overflow question.

    0 讨论(0)
提交回复
热议问题