knitr requires R 2.14.0 or better.
It will be supported in the
next version of RStudio
install.packages('knitr', dep=T)
require(knitr)
knit("myfile.Rnw") ## build myfile.tex
system("pdflatex myfile.tex") ## process it to make the pdf
purl("myfile.Rnw") ## extract R code into myfile.RTo decrease font size, redefine knitrout environment in the document header.
Set a default size for figures
\ifdefined\knitrout
\renewenvironment{knitrout}{\begin{footnotesize}}{\end{footnotesize}}
\else
\fi
\SweaveOpts{fig.width=4, fig.height=4}
\begin{document}
Code chunk options:
<<bwplot, fig=T, dev=pdf, fig.width=10, fig.height=4, out.height=.5\linewidth, out.width=.95\linewidth, cache =T>>= data(singer) bwplot(voice.part ~ height, data=singer, xlab="Height (inches)") @
Do not need to put lattice and ggplot commands within a print(...)
call as in Sweave.
Choose from many devices (png or tikz, for
example)
Set fig.height and fig.width to get axis labels to be
right proportional to plot window size. Smaller numbers make labels
bigger.
out.height and out.width relative to \linewidth or
\textwidth to get settings on the page.
Use cache=TRUE to avoid
repeatedly computing the same values.
Appendix: they sat to do this to show the code chunk from above.
<< ref.label=bwplot, echo=TRUE, results=markup>>= @
That does repeat the code, but also reruns it.
I would like to make code wrap at a larger number. Haven't figured that out yet.