I wanted to have code in Rmarkdown/slidify treated like a reveal.js fragment (moving in on click) but had trouble getting this to work without going to the HTML output and doing it manually. So these knitr hooks add the 'fragment' class to the pre tags if you include class="fragment
in the knitr heading. This also solves an issue I was having with slidify where I would try and globally set the opts_chunk$set(collapse=TRUE)
but many of my code fragments were not getting collapsed. This was not an issue in Rmarkdown but seemed to be an issue with slidify.
I run the hooks.R code using source()
in my Rmarkdown/slidify doc. Then in a knitr chunk I can include a class like this:
x <-1:100
Known issue: adding class="fragment" does not work with code chunks that have plots.