I am slowly converting to using Quarto instead of RMarkdown. One thing I still haven't figured out is if there is an equivalent to the RMarkdown setup chunk. E.g., I always used to start my RMarkdown documents with a chunk like
```{r setup}
library(tidyverse)
```
This would allow me to avoid seeing all the messages and warnings from packages when I knit the document, and made sure it would be run before things below. Is there something similar for Quarto? I have tried context: setup and label: setup but neither of them seem to do it.
I'm now realizing that the piece that might have hidden the messages and warnings was the default include=FALSE that the setup chunk usually came with. Maybe I should add that to my Quarto docs! The other piece still holds-- does label: setup or context: setup offer any of the benefits of the RMarkdown setup chunk?
Sorry for the no answer on this. Asking on Quarto Discussion (quarto-dev/quarto-cli · Discussions · GitHub) will often get you a more quicker response by the dev team, as Community member may not be able to help with all question here on Quarto.
setup chunk has a special meaning in the RStudio IDE I believe, when interactively running chunks. It was introduced first for Shiny Documents. I believe this why it gets confusing.
Initially it is context for shiny, which should be supported in Quarto to
but Chunk label are used as a shortcut instead of setting context. See explanation in
Above we’ve shown the use of the context attribute to associate chunks with various execution contexts. The label of R chunks can also serve as a shorthand way of specifying a context (e.g. a chunk with label setup automatically gains the context="setup" attribute).
That is why both label: setup or context: setup should work. However, in Quarto the former is no shorthand of the latter, so using context should probably be preferred.
Now I restarted R (to clean the environment) and executed only the second chunk with the tibble() function. R knows that it comes from loading library(tidyverse) in the setup chunk with the line label: setup but I received an error message with the line context: setup.
Hopefully, I could make clear my previous short post: #| label: setup worked, but #| context: setup did not work for me. Or the question posted: How do I have to apply the option context: to turn a code chunk to a setup code chunk?