0% found this document useful (0 votes)
52 views

Knitr Reference Card: 1 Syntax 3 Chunk Options

This document provides a reference card for knitr, an R package that allows embedding R code and output in documents. It summarizes knitr's syntax for different document formats, provides minimal examples, lists common chunk options, describes knitr functions, and lists additional knitr resources. The document is organized into sections on syntax, examples, chunk options, functions, and resources.

Uploaded by

ulysses_lp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

Knitr Reference Card: 1 Syntax 3 Chunk Options

This document provides a reference card for knitr, an R package that allows embedding R code and output in documents. It summarizes knitr's syntax for different document formats, provides minimal examples, lists common chunk options, describes knitr functions, and lists additional knitr resources. The document is organized into sections on syntax, examples, chunk options, functions, and resources.

Uploaded by

ulysses_lp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

knitr Reference Card

Yihui Xie

September 22, 2020

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 <!--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: https://yihui.org/knitr/
@ ˆ development repository: https://github.com/yihui/knitr (CRAN,
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

You might also like