Create a r script to render a Rmarkdown daily on a mac

I am trying to create a r script so it automatically renders a PDF Rmarkdown daily, but the log shows :

Error in -title : invalid argument to unary operator
Execution halted

Is there a different process for scheduling a markdown with an rscript?

Hi,

Welcome to the RStudio community!

Are you trying to run the markdown file directly from Rscript.exe? That is not possible, as you need to create an R script that then knits the markdown with the correct parameters (if needed).

rmarkdown::render("MyDocument.Rmd", params = list(
  year = 2017,
  region = "Asia",
  printcode = FALSE,
  file = "file2.csv"
))

Hope this helps,
PJ

Hi PJ,

Thanks for the reply

I am trying create a script that renders the Rmarkdown without having to press knit in the Rmarkdown.

So I would have to create a Rscrip to render the file, and then another Rscrip to create the job?

Thanks
Julio

Hi,

Yes so you have an R script like this:

myJob.R

rmarkdown::render("MyDocument.Rmd", params = list(
  year = 2017,
  region = "Asia",
  printcode = FALSE,
  file = "file2.csv"
))

Then you can call this script from any terminal

Rscript /path/to/script/myJob.R

And it will generate the Markdown

Or if you don't have any parameters you need to set you can combine it

Rscript -e "rmarkdown::render(\"MyDocument.Rmd\")"

PJ

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.