A few of us have been exploring on a twitter thread the idea that:
If you have a code block named 'setup' like
```{r setup} foo() ```
then every time you restart RStudio and execute any code in the middle of your markdown document, this block will be automatically run once before, i.e. your libraries will be loaded first.
Some people in the thread seem to be able to get this to work, but it doesn't work for me.
Here's a sort-of reprex as a github gist.
Using the reprex above, if I start a fresh R session, go to the test chunk and execute it without running the setup chunk first, I get an error (can't find function tibble
, which dplyr
should load). So it seems to me that the setup chunk is not automatically read in prior to running a subsequent chunk.
See further relevant tweets and possibly relevant answer from Alison.
I am using RStudio 1.3.959.
It's all a bit of a mystery. What am I missing?