Several ways to do this.
You can use the backtick-R piece in your YAML and specify the variables before rendering:
--- title: "`r thetitle`" author: "`r theauthor`" date: "July 14, 2015" --- foo bar.
Then:
R -e "thetitle='My title'; theauthor='me'; rmarkdown::render('test.rmd')"
Or you can use commandArgs() directly in RMD and feed them after --args :
--- title: "`r commandArgs(trailingOnly=T)[1]`" author: "`r commandArgs(trailingOnly=T)[2]`" date: "July 14, 2015" --- foo bar.
Then:
R -e "rmarkdown::render('test.rmd')" --args "thetitle" "me"
Here, if you called args R -e ... --args --name='the title' , your commandArgs(trailingOnly=T)[1] is the string "--name = foo" - it is not very smart.
In any case, I think you will want to check some kind of error / check by default. I usually do a compilation of a script, for example.
# compile.r args <- commandArgs(trailingOnly=T)
And then run R compile.r --args ... , supplying the arguments in the format in which I wrote my script for processing.
source share