opts_chunk controls global chunk options, e.g. opts_chunk$set(tidy = FALSE), format start end inline output which can be overridden by local chunk options. See all options at http://yihui. Rnw <<*>>= @ \Sexpr{x} TEX name/knitr/options; some frequently used options: Rmd ```{r *} ``` `r x` MD Rhtml <!--begin.rcode * end.rcode--> <!--rinline x--> HTML eval whether to evaluate the chunk Rrst .. {r *} .. .. :r:`x` reST echo whether to echo source code Rtex % begin.rcode * % end.rcode \rinline{x} TEX results 'markup', 'asis', 'hold', 'hide' Rasciidoc // begin.rcode * // end.rcode +r x+ AsciiDoc tidy whether to reformat R code Rtextile ### begin.rcode * ### end.rcode @r x@ Textile cache whether to cache results brew <% x %> text g.width, g.height, out.width, out.height device and output size of gures include whether to include the chunk results in output * denotes local chunk options, e.g. <<label, eval=FALSE>>=; x denotes inline R child lenames of child documents code, e.g. `r 1+2` (MD stands for Markdown) engine language name (R, python, . . . )
2 Minimal Examples 4 Functions
knit() the main function in this package; knit input document and write output 2.1 Sweave (*.Rnw) 2.2 R Markdown (*.Rmd) purl() extract R code from an input document spin() spin goat's hair (an R script with roxygen comments) into wool (a literate Hi _markdown_! programming document to be passed to knit()) \documentclass{article} stitch() insert an R script into a template and compile the document \begin{document} ```{r foo, echo=TRUE} knit_hooks$set() set or reset chunk and output hooks z = 1+1 Below is a code chunk. plot(cars) <<foo, echo=TRUE>>= ``` 5 Resources z = 1+1 plot(cars) The value of z is `r z`. homepage: http://yihui.name/knitr @ development repository: https://github.com/yihui/knitr (CRAN, Rforge) 2.3 Brew (*.brew) examples: https://github.com/yihui/knitr-examples The value of z is \Sexpr{z}. stackoverow: http://stackoverflow.com/tags/knitr/ \end{document} The value of pi is <% pi %>. mailing list: https://groups.google.com/group/knitr