Alexandre Halm
Alexandre Halm

Reputation: 989

How to embed and escape R Markdown code in a R Markdown document

I'm trying to write a memo on R Markdown syntax and as such I'd like to include in the document's output the R Markdown code and the output.

To be clear, I'd like the output to look something like:

~~~~~~~~~~~~~~~~~~
Including the following code chunk in the document:

```{r, eval=FALSE}
summary(cars)
```

will produce the following output:

summary(cars)

~~~~~~~~~~~~~~~~~~

I'm failing to escape the ``` and the {r, eval=FALSE}.

Upvotes: 4

Views: 1011

Answers (1)

Mehdi Nellen
Mehdi Nellen

Reputation: 9004

Maybe if you evaluate this:

```{r comment=NA}
cat("```{r, eval=FALSE}\nsummary(cars)\n```")
```

Upvotes: 2

Related Questions