Is there a way to make a parameter optional in R Markdown when using knitr? Below is a stand-alone example, my simple attempt to omit a parameter, and the error.
Example RMD file:
---
title: "`r params$name`"
date: \`r format(Sys.Date(), "%B %d, %Y")`\
output:
html_document:
toc: true
params:
name: NA
A: NA
B: NA
C: NA
---
# Header-1
`r params$A`
`r params$B`
```{r, echo=FALSE, out.width="50%"}
knitr::include_graphics(params$C)
```
Example run script:
render(input = "mytemplate.Rmd",
output_file = "fileout.html",
params = list(
name = 'Bob',
A = 'turkey',
B = 'otter'
)
)
Resulting error when omitting "C":
Error in knitr::include_graphics(params$C) :
Cannot find the file(s): NA