| format | start | end | inline | output |
|---|---|---|---|---|
| Rnw | <<*>>= | @ | \Sexpr{x} | TeX |
| Rmd | ```{r *} | ``` | `r x` | Markdown |
| Rhtml | <!--begin.rcode * | end.rcode--> | <!--rinline x--> | HTML |
| Rrst | .. {r *} | .. .. | :r:`x` | reST |
| Rtex | % begin.rcode * | % end.rcode | \rinline{x} | TeX |
| Rasciidoc | // begin.rcode * | // end.rcode | +r x+ | AsciiDoc |
| Rtextile | ### begin.rcode * | ### end.rcode | @r x@ | Textile |
| brew | <% x %> | text |
* denotes local chunk options, e.g.,<<label, eval=FALSE>>=;x denotesinline R code, e.g.,`r 1+2`.
\documentclass{article}\begin{document}Below is a code chunk.<<foo, echo=TRUE>>=z = 1 + 1plot(cars)@The value of z is \Sexpr{z}.\end{document}---title: "An R Markdown document"---Hi _Markdown_!```{r foo, echo=TRUE}z = 1 + 1plot(cars)```The value of z is `r z`.opts_chunk controls global chunk options, e.g.,knitr::opts_chunk$set(tidy = FALSE), which can be overridden by local chunkoptions. See all options athttps://yihui.org/knitr/options/. Some frequentlyused options are:
eval: whether to evaluate the chunkecho: whether to echo source coderesults:'markup','asis','hold','hide'tidy: whether to reformat R codecache: whether to cache resultsfig.width,fig.height,out.width,out.height: device and output sizeof figuresinclude: whether to include the chunk results in outputchild: path to child documentsengine: language name (R, python, …)knit(): the main function in this package; knit input document and writeoutputpurl(): extract R code from an input documentspin(): spin goat’s hair (an R script with roxygen comments) into wool (aliterate programming document to be passed toknit())stitch(): insert an R script into a template and compile the documentknit_hooks$set(): set or reset chunk and outputhooks