renv: make R environment reproducible

Adrian Joseph, PhD
7 min readJul 22, 2022

How to manage R dependencies and how to make sure that your code will keep working for as long as it needs to.

Photo by NOAA on Unsplash

R, as virtually every other programming language, uses dependencies. Even if you do not use anything but base R, you still have dependencies: the specific version of R you are using.

There are dependencies you can control, and others you cannot. You can control which version of R you want to use, which packages to use and their versions. You cannot really control dependencies like specific operative system libraries you might need, like the version of the C++ compiler. Changes to either of those two classes of dependencies can break your code. Today I’ll show you how you can address changes to dependencies you can control, and I’ll briefly mention a couple of solutions for changes to dependencies you cannot control.

The problem

Let’s start by considering two scenarios:

  1. In the first scenario, you have your code working. The code is fully tested and it has been running without any issue for months. Now, all of sudden, you start to see a failure, but you have not changed your code in a long time. What could it be? This can be extremely hard to debug. You check if the inputs have changed, but they haven’t, they are still what you would expect. After hours spent…

--

--