RSS Amplifier

deadSimpleTech blog feed · Jan 8, 2026

Using rv in a container

0
Sign in to vote or save

Iris Meredith · deadSimpleTech

In the interests of SEO and this being searched for easily, I've pulled out the section from my last chapter about using rv with Docker and edited it lightly for use as a reference.

rv is a new declarative command-line package manager for the R programming language written in Rust. Being declarative, I've found it to be far-and-away better at dependency resolution than any of the other package managers on the market, and being a command line tool rather than a tool to be called from inside an interactive R session makes it work much more agreeably with standard development workflows. In short, I really can't see myself recommending that anyone use any other tool for managing R dependencies any more.

As the tool is quite new and still undergoing active development, however, getting rv running in a container can take a bit of doing and there are few resources available that show you how to prepare a container image containing rv. R, being as charitable as possible, is quite responsive to the environment it runs in, so serious R developers will often use a reproducible development container when working with R. Having a clear guide for how to make rv work in a container would thus probably be a good thing to have, and it'd be good to have it available without having to read through three chapters of a book, so I've pulled a section out of the last chapter of R the Software Way and edited it for use as a standalone guide.

We can start the process by looking at a Dockerfile for an image containing rv:

1

FROM rocker/r-ver:4.5.2 AS base

RUN apt-get update

RUN apt-get install -y curl libcurl4-openssl-dev libicu-dev libtiff-dev make zlib1g-dev libssl-dev libx11-dev libxml2-dev libfontconfig1-dev libharfbuzz-dev libfribidi-dev libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev libwebp-dev pandoc

RUN curl -sSL https://raw.githubusercontent.com/A2-ai/rv/refs/heads/main/scripts/install.sh | bash

RUN mv ~/.local/bin/rv /usr/local/bin/rv

WORKDIR /r.the.software.way

COPY rproject.toml rproject.toml

COPY rv.lock rv.lock

RUN rv sync

RUN rv activate

In this case, we're assuming that we have a local project using rv, and we want to reproduce the current rv project inside a container. As there are basically zero cases where we want rv installed without R, I've used as a base one of the Rocker project's versioned R images: these are based on Ubuntu, so we'll be using apt as the package manager.

This being done, we next install a bunch of system dependencies. The tidyverse and devtools both depend on the presence of a number of system packages, and any serious developer is likely to need to use one or both of these. Unlike certain older package managers for R, rv will fail to install packages if system dependencies are absent (to be clear, this is a good thing), so we need to install the system dependencies into the image first.

Next, we install the rv executable in the usual way. There's a catch here, though: rv installs itself in a local user directory and adds itself to PATH using the .bashrc file (or the equivalent if you're using zsh or fish. On a development machine, that usually works fine, but in a container image, a lot of the infrastructure that rv takes for granted isn't present and the PATH variable often doesn't act as you might expect. We could try and alter PATH to make it work, but the easier option is simply to copy the executable (as rv is written in Rust, this is a single binary file) to where all of the other executables live using

1

RUN mv ~/.local/bin/rv /usr/local/bin/rv

This copies the executable from the place where rv installed it to /usr/local/bin/rv, which is one of the locations where executables can live on Unix-like systems.

Finally, we can copy across rproject.toml and rv.lock and then run rv sync to install exactly the same versions of exactly the same packages that you have installed locally into your container. We then run rv activate to activate the project, and we can build and run our container in the usual way.

Need an R expert who also knows her way around DevOps, containerisation and a whole bunch of other fun things? I'm on the lookout for opportunities. I'm mostly after consulting and contracting work, but I will consider the right permanent position.

Don't need an R expert but want to contribute to the income of a person who makes useful resources available for free? Donate to my Patreon or Liberapay, or make a one-off donation through Stripe.

Read the original on deadsimpletech.com

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.