Movatterモバイル変換


[0]ホーム

URL:


knitr Reference Card

Yihui Xie

2025-03-15

1 Syntax

formatstartendinlineoutput
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`.

2 Minimal Examples

2.1 Sweave (*.Rnw)

\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}

2.2 R Markdown (*.Rmd)

---title: "An R Markdown document"---Hi _Markdown_!```{r foo, echo=TRUE}z = 1 + 1plot(cars)```The value of z is `r z`.

3 Chunk Options

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:

4 Functions

5 Resources


[8]ページ先頭

©2009-2025 Movatter.jp