Materialize knitr params list?

If I have a parameterized knitr document with a yaml section with a params block like:

  foo: 123
  bar: baz

As I develop the document I might like to evaluate code blocks that refer to those variables interactively. But the params list is only materialized when I actually knit the document. As a result I put in a code block with eval=F duplicating the parameters. Then I can interactively evaluate that block when testing/developing, but it won't override the variables set in the yaml section if those are changed.

params <- list(foo=123, bar="baz")

Is there a better way to do this that doesn't involve duplicating the parameters?


I can use parameters interactively in my R console using the RStudio IDE, as described here:

"Parameters will not be available immediately after loading the file, but require any line of the report to be executed first"

For example, I can run all code in this document interactively without needing to knit:

There the parameters are (whitespace/indentation matters here):

  name1: "Alison" 
  name2: "Allison"

Aha! In my testing, I was using Command-Enter to execute lines of code, which does not materialize the params list, but if I execute a chunk with Command-Option-C, then the list is materialized. Thanks for setting me straight.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.