I am writing a book with Quarto and doing some analyses with R. Several analyses are pretty heavy, so I would not want to bother re-running them when I render the book (even if it's just run once and cached). However, for some lighter tasks I do want to use code, and some functions are run both in the heavy analyses and in the quarto document.
When I deploy the book via GitHub actions, I want to be able to automatically find the package dependencies needed to render the book without wasting cycles to get all the packages used in the entire repository.
The closest I've gotten is reading my _quarto.yml file, extracting the list of chapters, and feeding that to renv::dependencies. This gets me a list of package dependencies for each of the chapters.
However, the issue is that if I use box::use(my/own/module[function]), or even source(), the dependencies in the source file do not get picked up. I am not sure that a recursive search into a file's dependencies is in the scope of the renv package, so I am weary about asking for a feature request.
Can anyone suggest a solution? Does something like this already exist anywhere?
If these functions are still in the same folder then renv should be able to see them. I mostly use the functions renv::status(), renv::snapshot() - captures the packages used and versions installed, and renv::restore() - restores your versions to what is in the lockfile. I'm not using the renv::dependencies() function in my work flow.
renv doesn't follow source() calls, but as long as the files being sourced live within your project, that shouldn't be an issue.
Similarly, renv does implement support for divining package dependencies from box module usages, but it's possible that we're missing some cases -- a reproducible example would be helpful in determining more.
Another thing that can help is rendering the document in a clean environment. If something fails there, it's often easier to spot which file or package dependency was missed. It's a nice sanity check before automating the whole workflow.