-
-
Save yihui/1803930 to your computer and use it in GitHub Desktop.
% 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} |
Thanks for response and link to news of v0.6. Development version not easy to install under Windows, (no Rtools for R-2.15.0, spaces in paths problem, too much). Maybe come back when 0.6 is on CRAN.
I have pushed a version to R-Forge, so you should be able to install the Windows version once the build is ready there: https://r-forge.r-project.org/R/?group_id=656
Would you have a beamer example with references working properly for figures and tables?
The reference bit works, but the label does not print in the figure caption:
<<Figure1, fig.cap = 'My Figure'>>=
...etc.
plot(x, y)
@
\end{frame}
The above has a caption like: Figure: My Figure instead of Figure 1: My Figure
This \ref{fig:Figure1} prints as Figure 1, as expected.
And how to do the same with a table, e.g.
<<Table1, echo = FALSE, results = 'asis'>>=
library(xtable)
xtable(summary(lm(y~x))$coefficients, caption ="Summary")
@
Couldn't get it to work at all inside the beamer class.
Thanks!
you need to install the development version; this will be a new feature in v0.6: https://github.com/yihui/knitr/blob/master/NEWS