Beamer

Using knitr in beamer slides

2011-12-08

It is straightforward to use Sweave or knitr with beamer; the only thing you need to be careful of is you have to add the fragile option to the frames that contain verbatim code. For LyX users, make sure you use the latest version of LyX (>= 2.1.2), and then you can use the FragileFrame environment instead of a standard Frame environment.

One note on the Rnw source for users who came before knitr 0.6 – in the past I used this in the preamble:

\ifdefined\knitrout
  \renewenvironment{knitrout}{\begin{footnotesize}}{\end{footnotesize}}
\else
\fi

It will wrap the knitr output in a footnotesize environment, but since knitr 0.6, a single global option size will control the font size of the whole chunk, and this trick is no longer needed.

How about HTML5 slides?

You can actually also try HTML slides, which smell fancy and modern. I have a rough tutorial here.