This is a mutliple step process. renv activates automatically because there is a project .Rprofile
that will trigger the renv
project by loading the script in the renv
folder. So this is the whole renv infrastructure that should be in Quarto book.
A quarto project is a folder with a _quarto.yml
- and R process will be run from this root folder. So that is where .Rprofile
and other renv
stuff should be if you want to use that.
There is no way to tell Quarto to use another project folder for its R process, but maybe you can trick R and renv to load the project in parent folder.
Idea is :
- R working dir when Quarto run R code will be your Quarto project. So .Rprofile will be run there if there is one.
- You could try tweak this .Rprofile to load renv knowing that the infrastructure is elsewhere.
Does the book require some content from the analysis ? so from a parent folder ?
I think I would consider myself two organisations:
-
Have my analysis as a folder inside my Quarto book project, and make that folder so it is ignored by Quarto (so that it won't look for book chapter into it or something else). Then have my book elsewhere in the folder (file at root or inside another folder), and use config to explicit
chapters
-
Or consider Analysis and book as two different project, in the sense that Analysis will always run before rendering the book. I would have outputs from my analysis useful to Quarto book stored in specific database file (.rds file, arrow parquet/feather for data.frame, or other DB storage). Quarto book would only read results in there for what it needs to do. This would allow two renv project - one for Analysis and one for Book.
This type of workflow is closed to what tools like targets offers.
A third option is what I mentioned before : Understand how R works at startup to configure the necessary setup in .Rprofile which will be run for each R process started from your Quarto root project.
Just ideas.
Hope it helps