When you’re writing about RMarkdown using RMarkdown you may run into trouble when the RMarkdown parser parses the code you want to be simply embedded in your site.

Let’s say you want to show a simple Rmd-file like this

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
---
title: "Demo Document"
author: "rstats"
date: "29 6 2020"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown

```{r pressure, echo=FALSE}
plot(pressure)
```

If you put the above code into your RMarkdown-page (like this blogdown article) the code-chunks (lines 8-10 and 14-16) will be run by R and the output is put into your article.

So you have to mask it.

First you have to surround the whole code with

1
2
3
````markdown
put RMarkdown code here
````

Every R code chunk must be preceded with `r ''`.

So you get

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
````markdown
---
title: "Demo Document"
author: "rstats"
date: "29 6 2020"
output: html_document
---

`r ''````{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown

`r ''````{r pressure, echo=FALSE}
plot(pressure)
```
````

Another way is to include the code using readLines().

1
2
3
````
`r paste(readLines('demo.Rmd'), collapse = '\n')`
````