safer-r / saferDev

GNU General Public License v3.0
0 stars 0 forks source link

In vignettes, the chunks are executed during CI, but results are in the same displayed chunk in the page -> not easy to copy-paste the code #10

Open gael-millot opened 7 months ago

gael-millot commented 7 months ago

See for instance https://safer-r.github.io/saferDev/articles/arg_check.html

gael-millot commented 2 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 Section Title


# 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.