What defines the setup chunk?

You are right- the links are scarce on this one. Here is a snippet from R4DS:

"There is one chunk name that imbues special behaviour: setup . When you’re in a notebook mode, the chunk named setup will be run automatically once, before any other code is run."

And a bit more from R Markdown: The Definitive Guide in the Notebooks chapter:

"If it is necessary to execute notebook chunks in a different directory, you can change the working directory for all your chunks by using the knitr root.dir option...This option is only effective when used inside the setup chunk."

6 Likes