Skip to content

Instantly share code, notes, and snippets.

@baptiste
Last active February 15, 2023 20:29
Show Gist options
  • Save baptiste/cdd86df690597d98947ce811e45b98fb to your computer and use it in GitHub Desktop.
Save baptiste/cdd86df690597d98947ce811e45b98fb to your computer and use it in GitHub Desktop.
code externalisation in quarto
---
title: "file 1"
format: html
---
## Code Externalisation
Write R code in external R scripts, and use `read_chunk()` to read them into the current document.
```{r cache=FALSE}
knitr::read_chunk('script.R')
```
The following two chunks are from the external R script `script.R`:
```{r test-a}
```
```{r test-b}
```
---
title: "file 2"
format: html
---
## Code Externalisation, second file
Write R code in external R scripts, and use `read_chunk()` to read them into the current document.
```{r cache=FALSE}
knitr::read_chunk('script.R')
```
The following two chunks are from the external R script `script.R`:
```{r test-a}
```
```{r test-b}
```
# ---- test-a ----
1 + 1
x = rnorm(10)
# ---- test-b ----
mean(x)
sd(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment