But that’s not what I’m talking about today. Today I want to talk about using docker to debug an R package that is throwing an error in the development version of R. This came up because with the new GitHub Actions infrastructure, I can now test my R packages on multiple OSs and with multiple versions of R, and today R/qtl was shown to throw an error in R-devel.
If you look at the test history, you’ll see I was mostly screwing around trying to get LaTeX installed and then trying to get all of the needed LaTeX packages for a 10-year-old Sweave-based vignette. And I got through that only to find that there was a different actual R problem that needed to be fixed.
Not wanting to install the development version of R on my machine, I pondered cloud installations, and then thought, “Hmm, this seems like a good application for docker. I just need to find a docker container with R-devel, install R/qtl, and then try it out.” And well, it was pretty simple.
Install Docker. See the official instructions. I’m working on a Ubuntu laptop, so I did:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable" sudo apt update sudo apt install docker-ce docker-ce-cli containerd.io
Dockerfilewhich builds off rocker/r-devel and installs the package to be tested. (In this rocker image,
Ris the current version of R and
RDis the devel version, so we need to use
RDto install the package.)
FROM rocker/r-devel RUN RD -e "install.packages('qtl')"
Build the docker image.
sudo docker build -t rdevel-qtl .
Fire up that image in a container.
sudo docker run -it rdevel-qtl bash
Run R and load the package.
The above puts you into a bash shell within the container. Type
RDto fire up the devel version of R, and then load your package and mess about. I quickly saw where I went wrong.
Fix the problem and test it.
I should add a formal test of this bug, and I should also look for all other possible instances of this problem. (I blanche to think of them.)
But for now I just plunged in and fixed it, pushed the change to GitHub, and then tested it out in my container by installing the repaired version with the remotes package.
There’s a lot more that one can do with Docker, but this was a pretty quick and satisfying experience poking around in the development version of R to fix a bug in my ancient and creaky package.
I gave a talk about docker in my Advanced Data Analysis course last spring. You can look at the slides, including a version with notes of what I said, and watch the lecture. (It’s recommended that you do so on fast-forward.) The course resources page points to other resources on docker.