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
.
If you don't want any code chunks to run you can add eval = FALSE in your setup chunk with knitr::opts_chunk$set() . If you want only some chunks to run you can add eval = FALSE to only the chunk headers of those you don't want to run.
You use results="hide" to hide the results/output (but here the code would still be displayed). You use include=FALSE to have the chunk evaluated, but neither the code nor its output displayed.
If you prefer to use the console by default for all your R Markdown documents (restoring the behavior in previous versions of RStudio), you can make Chunk Output in Console the default: Tools -> Options -> R Markdown -> Show output inline for all R Markdown documents .
include = FALSE prevents code and results from appearing in the finished file. R Markdown still runs the code in the chunk, and the results can be used by other chunks. echo = FALSE prevents code, but not the results from appearing in the finished file. This is a useful way to embed figures.
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
```
````
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With