knitr Reference Card
Yihui Xie September 8, 2021
1 Syntax 3 Chunk Options
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 https: Rnw <<*>>= @ \Sexpr{x} TEX //yihui.org/knitr/options/; some frequently used options: Rmd ```{r *} ``` `r x` MD Rhtml 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. <
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) <
1