Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnstantongeddes/a427dc550189c327ab9c to your computer and use it in GitHub Desktop.
Save johnstantongeddes/a427dc550189c327ab9c to your computer and use it in GitHub Desktop.
How to get verbatim R chunks in R markdown. Again. Writing it down now.
---
title: "Get verbatim R chunks in R Markdown"
author: "Jenny Bryan"
date: "18 September, 2014"
output:
html_document:
keep_md: TRUE
---
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](https://github.com/yihui/knitr/blob/master/FAQ.md):
`r ''` ```{r label, what=ever}
From [issue 443](https://github.com/yihui/knitr/issues/443)
`r ''````{r foo}
print('hello world!')
```
From [`knitr` example 065](https://github.com/yihui/knitr-examples/blob/master/065-rmd-chunk.Rmd), involving inline R code:
```{r eval=TRUE}`r ''`
n = 10
rnorm(x)
```
Also from [`knitr` example 065](https://github.com/yihui/knitr-examples/blob/master/065-rmd-chunk.Rmd), involving a zero-width space:
`​``{r eval=TRUE}
n = 10
rnorm(n)
```
From [Karl Broman](https://gist.github.com/kbroman/ca560b967b0b7a08a3b2), involving `<pre>` and `<code>` tags:
<pre><code>```{r whatever}
data(cars)
summary(cars)
```</code></pre>

Get verbatim R chunks in R Markdown

Jenny Bryan
18 September, 2014

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 label, what=ever}

From issue 443

```{r foo}
print('hello world!')
```

From knitr example 065, involving inline R code:

```{r eval=TRUE}
n = 10
rnorm(x)
```

Also from knitr example 065, involving a zero-width space:

`�``{r eval=TRUE}
n = 10
rnorm(n)
```

From Karl Broman, involving <pre> and <code> tags:

```{r whatever}
data(cars)
summary(cars)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment