```{=html}

## Syntax

| 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` denotes
inline R code, e.g., `` `r 1+2` ``.

## Minimal Examples

::: col-2
### Sweave (\*.Rnw)

``` tex
\documentclass{article}
\begin{document}

Below is a code chunk.

<<foo, echo=TRUE>>=
z = 1 + 1
plot(cars)
@

The value of z is \Sexpr{z}.
\end{document}

R Markdown (*.Rmd)

---
title: "An R Markdown document"
---

Hi _Markdown_!

```r
z = 1 + 1
plot(cars)
```

The value of z is `r z`.

:::

Chunk Options

opts_chunk controls global chunk options, e.g., knitr::opts_chunk$set(tidy = FALSE), which can be overridden by local chunk options. See all options at https://yihui.org/knitr/options/. Some frequently used options are:

Functions

Resources

{css, echo=FALSE} body { max-width: none; } table { width: 100%; } .body h2 { border-bottom: none; font-size: 1.3em; } .body, .col-2 { columns: 2; & > :first-child { margin-top: 0; } }



yihui/knitr documentation built on Nov. 14, 2024, 3:14 p.m.