5

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?

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
balin
  • 1,554
  • 1
  • 12
  • 26
  • 1
    You can just use 2 levels and the second levels name has to be `value`. Try this: `params: first_level: value: ~`. Changing `value` to `second_level` will give the error ... – J_F Nov 14 '17 at 12:01
  • Making the content of `first_level` into `!r list(second_level = NULL)` produces what I want/expect, but defeats the use of `yaml` to begin with ... – balin Nov 14 '17 at 12:12
  • 1
    I think this is a bug of the RStudio IDE (because `rmarkdown::render()` works). You may file it to https://github.com/rstudio/rstudio/issues. Thanks! – Yihui Xie Nov 14 '17 at 15:32
  • 1
    Thanks @YihuiXie. [Done](https://github.com/rstudio/rstudio/issues/1752). – balin Nov 14 '17 at 19:32

1 Answers1

2

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.

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419