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.
One hacky solution I have found is to hardcode the html output directly in the documentation like this
## All results
```{r loopResults, echo=FALSE, results='asis'}
results = list(result1 = data.frame(x=rnorm(3), y=rnorm(3)), result2=data.frame(x=rnorm(3), y=rnorm(3)))
for(res in names(results)) {
cat(paste("<h3>Results for: ", res, "</h3>>"))
plot(results[[res]]$x, results[[res]]$y)
}
This doesn't seem to be the right way to do things, especially since I want to create PDF documents via pandoc at time and would have to change the hard-coded expressions. (I have currently convenience functions like h3(text, type)).
Is there a better way of doing this?
pandoc
you might find the packagepander
useful. In particular the function?pander::pandoc.header
might be of interest. – Trackandfield<h3>
; you should use the markdown syntax###
for h3 instead: en.wikipedia.org/wiki/Markdown#Headings – AdmireRmd
will be the cleanest. If you have a lot of markup inside the loop, then using abrew
template as an intermediate will lead to a cleaner solution. – Allveta