%% LyX 2.2.1 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[10pt]{beamer}
\usepackage[T1]{fontenc}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\usepackage{url}
\ifx\hypersetup\undefined
  \AtBeginDocument{%
    \hypersetup{unicode=true,pdfusetitle,
 bookmarks=true,bookmarksnumbered=false,bookmarksopen=false,
 breaklinks=false,pdfborder={0 0 0},pdfborderstyle={},backref=false,colorlinks=false}
  }
\else
  \hypersetup{unicode=true,pdfusetitle,
 bookmarks=true,bookmarksnumbered=false,bookmarksopen=false,
 breaklinks=false,pdfborder={0 0 0},pdfborderstyle={},backref=false,colorlinks=false}
\fi
\usepackage{breakurl}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
\providecommand{\LyX}{\texorpdfstring%
  {L\kern-.1667em\lower.25em\hbox{Y}\kern-.125emX\@}
  {LyX}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
 % this default might be overridden by plain title style
 \newcommand\makebeamertitle{\frame{\maketitle}}%
 % (ERT) argument for the TOC
 \AtBeginDocument{%
   \let\origtableofcontents=\tableofcontents
   \def\tableofcontents{\@ifnextchar[{\origtableofcontents}{\gobbletableofcontents}}
   \def\gobbletableofcontents#1{\origtableofcontents}
 }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usetheme{PaloAlto}

\makeatother

\begin{document}
<<setup, include=FALSE>>=
library(knitr)
opts_chunk$set(fig.path='figure/beamer-',fig.align='center',fig.show='hold',size='footnotesize')
@

\title[knitr, Beamer, and FragileFrame]{A Minimal Demo of knitr with Beamer and Fragile Frames}

\author{Yihui Xie\thanks{I thank Richard E. Goldberg for providing this demo.}}
\makebeamertitle
\begin{frame}{Background}

\begin{itemize}
\item The \textbf{knitr}\textbf{\emph{ }}package allows you to embed R code
and figures in \LaTeX{} documents

\begin{itemize}
\item It has functionality similar to Sweave but looks nicer and gives you
more control
\end{itemize}
\item If you already have Sweave working in \LyX{}, getting \textbf{knitr}
to work is trivial

\begin{enumerate}
\item Install the \textbf{knitr} package in \emph{R}
\item Read \url{https://yihui.name/knitr/demo/lyx/}
\end{enumerate}
\item If you use Sweave or \textbf{knitr} with Beamer in \LyX{}, you must
use the\emph{ FragileFrame} environment for the frames that contain
R code chunks. Let's see if \textbf{knitr} works with Beamer in this
small demo. 
\end{itemize}
\end{frame}

\section{First Test}
\begin{frame}[fragile]{First Test}

OK, let's get started with just some text:

<<echo=FALSE,results='hide'>>=
# some setup
options(width=60)  # make the printing fit on the page
set.seed(1121)   # make the results repeatable
@

<<>>= 
# create some random numbers
(x=rnorm(20))  
mean(x);var(x)  
@

BTW, the first element of \texttt{x} is \Sexpr{x[1]}. (Did you notice
the use of\texttt{ \textbackslash{}Sexpr\{\}}?)
\end{frame}

\section{Second Test}
\begin{frame}[fragile]{Second Test}

Text is nice but let's see what happens if we make a couple of plots
in our chunk:

<<boring-plots,fig.width=4,fig.height=4,out.width='.45\\linewidth'>>=
par(las=1,mar=c(4,4,.1,.1))  # tick labels direction
boxplot(x) 
hist(x,main='',col="blue",probability=TRUE) 
lines(density(x),col="red")
@
\end{frame}

\section{The Big Question}
\begin{frame}{The Big Question}

Do the above chunks work? You should be able to compile the \LyX{}
document and get a nice-looking PDF slide presentation. If not, time
to double-check everything...
\end{frame}

\end{document}
