Rmarkdown: programmatically program block options?

Is it possible to take the rmarkdown file, programmatically manipulate the chunk parameters, and then knit based on the changed document?

I have some rmarkdown files that I want to use purl , including all the code (even those that have eval=FALSE ).

At this point, I think that I could (1) use sed to switch eval=FALSE to eval=TRUE , and then (2) purl . But I would like if there was something nicer, for example, maybe, for example:

 parsed_rmd <- knitr::parse_rmd('my_rmarkdown.rmd') for (chunk in parsed_rmd) { chunk$eval <- TRUE } knitr::purl(parsed_rmd, output = 'my_rmarkdown_as_r.R' 
+6
source share
1 answer

You can set "echo" to a logical condition based on a parameter.

Create an Rmarkdown (.Rmd) file and define the parameter in the YAML header:

 params: show_optional: no 

Set the echo parameter for a piece of code that you do not want to show in order to check the value of this parameter:

 ```{r optional_code, echo = (params$show_optional == "Yes")} # chunk with code you only want to show sometimes ``` 

Then call rmarkdown_render with the appropriate parameter:

 rmarkdown::render(file = "myreport.rmd", params = list(show_optional = "yes") 

More about options

see http://rmarkdown.rstudio.com/developer_parameterized_reports.html .
0
source

All Articles