In R Markdown, is there a way to change the echo
option for different output types?
In the example below, I'd like to show my code on the html_document
output (echo = TRUE
), but would like to hide the code on the word_document
output (echo = FALSE
).
Currently, I have the global option to define knitr::opts_chunk$set(echo = TRUE)
in my first code chunk, which seems to be required for the html_document
code_folding
option in the YAML header, but this also shows the code in the word_document
output. If I remove this global option, I see the same outcome. Is there a way to define the echo option in the YAML header, under each of the output types (word_document
vs. html_document
)?
Thanks for your help with this.
---
title: "test2"
author: "Carina"
date: "February 13, 2020"
output:
word_document: default
html_document:
code_folding: show
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```