This article is reposted from a gist with the kind permission of Jenny Bryan.
My periodic revisitation of “how can I include a verbatim R chunk in .rmd
”? This time I am writing it down! Various proposed solutions:
From the knitr
FAQ:
`r ''` ```{r label, what=ever}
```{r label, what=ever}
From issue 443
`r ''````{r foo}
print('hello world!')
```
```{r foo}
print('hello world!')
```
From knitr
example 065, involving inline R code:
```{r eval=TRUE}`r ''`
n = 10
rnorm(x)
```
```{r eval=TRUE}
n = 10
rnorm(x)
```
Also from knitr
example 065, involving a zero-width space (copy and paste the input code into the RStudio editor to see the zero-width space after the first back tick):
```{r eval=TRUE}
n = 10
rnorm(n)
```
```{r eval=TRUE}
n = 10
rnorm(n)
```
From Karl Broman, involving <pre>
and <code>
tags:
<pre><code>```{r whatever}
data(cars)
summary(cars)
```</code></pre>
```{r whatever}
data(cars)
summary(cars)
```