Search code examples
rr-markdownblogdown

Display YAML and chunks without executing them in blogdown


In an article made with blogdown, I would like to show the YAML and some chunks I used in a previous work. Therefore, I would like to display them without executing them, just as-is. I tried to embed the YAML and the chunks with 4 backticks but the execution of chunks still depends on their options. Here's an example:

---
title: ""
author: ''
date: ""
output:
  blogdown::html_page
---
  
Display a fake YAML and a fake chunk:
````
---
title: ""
author: ''
date: ""
output:
  pdf_document
---
```{r}
1 + 1
```
````

As you can see, the chunk containing 1+1 is executed. This is what should be displayed:

---
title: ""
author: ''
date: ""
output:
  pdf_document
---
```{r}
1 + 1
```

How can I do that? If it matters, the extension of my file is .Rmarkdown, and not .Rmd.


Solution

  • I had a look in the source of the RMarkdown book. Besides the four backticks the trick is to put

    `r ''`
    

    in front of the code chunk. Try this:

    ---
    title: "Untitled"
    output: html_document
    ---
    
    ````markdown
    ---
    title: ""
    author: ''
    date: ""
    output:
      pdf_document
    ---
    `r ''````{r}
    1 + 1
    ```
    ````