Switch branches/tags
Nothing to show
Find file Copy path
55 lines (44 sloc) 1.48 KB
%% for inline R code: if the inline code is not correctly parsed, you will see a message
\newcommand{\rinline}[1]{SOMETHING WRONG WITH knitr}
%% begin.rcode setup, include=FALSE
% library(knitr)
% opts_chunk$set(fig.path='figure/latex-', cache.path='cache/latex-')
%% end.rcode
Boring stuff as usual:
%% a chunk with default options
%% begin.rcode
% 1+1
% x=rnorm(5)
%% end.rcode
For the cached chunk below, you will need to wait for 10 seconds for
the first time you compile this document, but it takes no time the
next time you run it again.
%% chunk options: cache this chunk
%% begin.rcode my-cache, cache=TRUE
% set.seed(123)
% x = runif(10)
% sd(x) # standard deviation
% Sys.sleep(10) # test cache
%% end.rcode
Now we know the first element of x is \rinline{x[1]}. And we also know
the 26 letters are \rinline{LETTERS}. An expression that returns a
value of length 0 will be removed from the output, \rinline{x[1] =
2011; NULL} but it was indeed evaluated, e.g. now the first element
of x becomes \rinline{x[1]}.
How about figures? Let's use the Cairo PDF device (assumes R $\geq$
%% begin.rcode cairo-scatter, dev='cairo_pdf', fig.width=5, fig.height=5, out.width='.8\\textwidth'
% plot(cars) # a scatter plot
%% end.rcode
Warnings, messages and errors are preserved by default.
%% begin.rcode
% sqrt(-1) # here is a warning!
% message('this is a message you should know')
% 1+'a' # impossible
%% end.rcode