I want to iterate over a list of result-sets in my R markdown file. When I produce the output I want to include some text like headers with the name of the result set.
I would use a combination of brew
and knitr
to achieve this. I would create a brew template called doc.brew
which looks like this
<% for (res in names(results)) { -%>
### Results for: <%= res %>
```{r}
plot(results[["<%= res %>"]]$x, results[["<%= res %>"]]$y)
```
<% } %>
You can now run the following code to get your desired output
results = list(
result1 = data.frame(x=rnorm(3), y=rnorm(3)),
result2=data.frame(x=rnorm(3), y=rnorm(3))
)
brew::brew('doc.brew', 'doc.Rmd')
knit2html('doc.Rmd')