Btibert3
2/11/2012 - 8:07 PM

Another minimal beamer example for knitr

Another minimal beamer example for knitr

% this is a simplified version of 
% https://github.com/yihui/knitr/blob/master/inst/examples/knitr-beamer.Rnw
\documentclass{beamer}
\begin{document}
<<setup, include=FALSE>>=
# smaller font size for chunks
opts_chunk$set(size = 'footnotesize')
@
\title{A Minimal Demo of knitr}
\author{Paul Hiemstra \and Yihui Xie}

\maketitle

% very important to use option [fragile] for frames containing code output!

\begin{frame}[fragile]
You can test if \textbf{knitr} works with this minimal demo. OK, let's
get started with some boring random numbers:

<<boring-random>>=
set.seed(1121)
(x=rnorm(20))
mean(x);var(x)
@
\end{frame}

\begin{frame}[fragile]
The first element of \texttt{x} is \Sexpr{x[1]}. Boring boxplots
and histograms recorded by the PDF device:

<<boring-plots, fig.width=5, fig.height=5, out.width='.45\\linewidth', fig.show='hold'>>=
## two plots side by side (option fig.show='hold')
boxplot(x)
hist(x,main='')
@
\end{frame}

\end{document}