Local Linux checks with Docker

  collapse = TRUE,
  comment = "#>"


Scenario: there's a bug in the check results of your package on a CRAN Linux platform, or you saw such a bug even before CRAN submission, by building your package on a R-hub Linux platform. How can you reproduce and fix the bug? Submitting to the R-hub platform (or the R-hub platform that's closest to the CRAN platform) after each tweak of your code would have a high turnaround so is not optimal for debugging. R-hub's Linux Docker images are available for you to use, so you can run the R-hub Linux builders locally.

Warning: at the moment, the functions are not tested on Windows! Bug reports are welcome :-)

Install and get to know Docker

To be able to use the feature, you will need to install Docker. Please refer to Docker docs. On Windows, installation might be trickier, check that your machine meets the system requirements. On Linux, make sure to run the post-installation steps to make the docker command available to your user without the sudo prefix.

If you are new to Docker, for the basic use shown in the next two sections you don't need to learn anything, you won't have to leave R. Nonetheless, if you're curious, this tutorial features a nice introduction. Also see this blog post and the list of resources it shows at the end.

List R-hub Linux images

Each of R-hub Linux platforms is associated to a Docker image, whose Dockerfile is stored in the r-hub/rhub-linux-builders repository, and that is built and available on Docker Hub. Note, if you're used to using Docker images outside of R, you might want to just refer to the information in R-hub Linux Docker images GitHub repository (including links to the built images on Docker Hub). The advantage of using the rhub package instead of Docker directly, is that the package will install the system requirements properly.

To list the available images from R, you can use the local_check_linux_images() function that returns a data.frame and has a pretty default printing.

imgs <- local_check_linux_images()
knitr::kable(imgs, row.names = FALSE)

Of particular interest are

In theory, you could also use images that are not listed in the list above, e.g. your own Docker images.

Run local checks

Below we'll start a check of a package on the "rhub/debian-gcc-release" image (Debian Linux, R-release, GCC). The first time you use an image on your machine, it'll be downloaded from Docker Hub, which might take a while. The image won't be deleted after use, so next time will be faster until you clean up your machine's Docker images, which one should do once in a while (note that R-hub images are regularly updated).

pkg_path <- "/home/maelle/Documents/R-hub/test-packages/note"
local_check_linux(pkg_path, image = "rhub/debian-gcc-release")

You can either just run the check as shown above, which will print a log to the screen, including R CMD check results in the end, or assign it to an object:

pkg_path <- "/home/maelle/Documents/R-hub/test-packages/note"
chk <- local_check_linux(pkg_path, image = "rhub/debian-gcc-release")

The object returned is of the class rcmdcheck::rcmdcheck which is an S3 object with fields errors, warnings and notes (character vectors), that you could operate on if you wish.

The local_check_linux() function creates a container (instance of the image) that won't be deleted after use so you might want to clean up once in a while.

Do more with R-hub Linux images

If running checks in images iteratively isn't enough for your debugging, you might want to run the container created by local_check_linux(). Take note of the container name and run (in a shell, not in R)

docker container start 7181196d-bc3c-4fc8-a0e8-dc511150335d-2
docker exec -it 7181196d-bc3c-4fc8-a0e8-dc511150335d-2 bash

where 7181196d-bc3c-4fc8-a0e8-dc511150335d-2 is the container name, this is printed out by local_check_linux(). After running these commands, you will get a shell within the Docker container, where you can run R. Note that on some containers R is installed in /opt/.

For more information, you may want to look at the shell script that rhub uses to set up the container for running the check. To find it, run the code below.

system.file(package = "rhub", "bin", "rhub-linux-docker.sh")

Try the rhub package in your browser

Any scripts or data that you put into this service are public.

rhub documentation built on May 2, 2019, 3:44 p.m.