Open gael-millot opened 7 months ago
Use Code Folding
One approach is to use the code_folding option in your R Markdown document's YAML header to make the code collapsible. This allows users to expand and copy the code easily.
yaml
output: rmarkdown::html_vignette: code_folding: hide
With code_folding: hide, the code chunks are hidden by default but can be toggled by the user to show them. Separate Code and Results in Different Chunks
By manually separating the code from the results, you can display only the results in one chunk while providing the code separately for easy copy-pasting. Here's an example of how you could structure it: R Markdown Example
markdown
# Your code here
text
# Your code here
php
In this setup:
- The first chunk (`eval=FALSE`) displays the code but does not execute it.
- The second chunk (`echo=FALSE`) runs the code without displaying it, showing only the results.
### Use `knitr::opts_chunk`
You can also adjust chunk options globally by setting `knitr::opts_chunk$set()` at the beginning of your document to control the appearance of your chunks throughout the document.
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, eval = TRUE, include = TRUE)
Modify these options as required to globally control chunk behavior.
See for instance https://safer-r.github.io/saferDev/articles/arg_check.html