Source specific code chunks from RMarkdown

You could also work with knitr::read_chunk:
16.3 Read multiple code chunks from an external script (*) | R Markdown Cookbook (bookdown.org)

Instead of source("~/R/dbConnections.R") you would call knitr::read_chunk("~/R/dbConnections.R") and then call your connections like this (if you called your chunks con-a, con-b...):

```{r, con-a}
```{r, con-b}
1 Like