Can you use {renv} on a per-blogpost basis?

I'd like to use {renv} on a per post basis in a {blogdown} or {distill} blog. Is this possible and is there a recommended workflow?

I want to be able to rebuild individual posts (or the entire blog) in future, but I know that it might fail if I've updated packages globally since the original publication.

I assume this would involve a renv.lock file within the page bundle for each given post (i.e. in _post/YYY-MM-DD-post-name/ for a {distill} blog), but is there a way to install/load packages on a per post basis with {renv} when it comes to rebuilding a post/the whole site?

Feels like this is necessary for a truly reproducible experience. Or perhaps I'm missing something?

Edit (2022-03-22): I wrote about an approach using {renv} 'profiles' that you might find useful.

FWIW there is an open discussion about this in blogdown

Currently there is no built in way but I believe you could use a main R script (or a Makefile) that would allow to do that, but maybe that is not easy.

For blogdown, new v1 version has better workflow and does not rebuild by default. So once your post is built, it won't be rebuild unless you change something. That reduce the need for locking R environment. See Announcing blogdown v1.0 - Posit

One of the drawback of having one renv environment per post is that the project would become heavy and not so easy to render. Each post would need to be rendered separatly in its own document. But as I said I thing this would be possible by improving the tooling both in renv and rmarkdown ecosystem.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.