While using a single level list/dictionary for parameterizing an rmarkdown
document works:
---
params:
first_level: ~
---
```{r}
params
```
and knitting returns the expected
## $first_level
## NULL
I'm unable to use multi-level list/dictionaries as knitting
---
params:
first_level:
second_level: ~
---
```{r}
params
```
produces Error: no value field specified for YAML parameter 'first_level'
Execution halted
, where I would expect
## $first_level
## $first_level$second_level
## NULL
Is there really only a single level list supported or what am I screwing up?
As I commented below, the expected output can be achieved using
---
params:
first_level: !r list(second_level = NULL)
---
```{r}
params
```
But why use yaml
then at all in place of a parametrizing code block?
params
is a special field for R Markdown, and you must use one of the two ways to specify the value of a parameter: if the value is not a list (e.g., a scalar), you can specify it using the normal YAML syntax; however, if it is a list, R Markdown expects a sub-field named value
, and the value must be specified in this sub-field. In your case, you must use a value
field, e.g.,
---
params:
first_level:
value:
second_level: ~
---
```{r}
params
```
That is currently by design.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With