If you want to submit your R package to CRAN, you need to ensure that all R checks will be executed successfully without a warning for the current and the devel version of R.
Not only that but as a package maintainer, you also need to ensure that your submitted packages will still work with upcoming R versions. If you are using native code in your package which needs compilation (e.g. C/C++), the whole process is even getting more complex, since you need to ensure that the compilation of the code works on different systems (debian, fedora, windows (32 and 64 bit), solaris (sic), and osx) and with different compilers (gcc, clang).
But, for the moment let’s focus on setting up an environment to check your package against the latest R-Devel version to be able to reproduce and resolve issues.
Building an R-Devel Docker image
Installing the latest R-Devel version means usually pulling and compiling the latest R code. If you don’t want to clutter your system with new dependencies and if you want to have a new clean R-Devel installation, I’d recommend using Docker containers for testing your package.
On the Docker hub you can find the rocker/r-devel:latest Docker image, however contrary to its name (or tag), it usually doesn’t contain the latest R-Devel code (at the time of writing this article, the last image was pushed 2 months ago). That shouldn’t stop you from using Docker though, since we can simply use the recipe (aka Dockerfile), to build our image.
|
|
Next, we build a Docker image named r-devel-local
using the downloaded Dockerfile.
|
|
Congrats. You’ve built a Docker image that contains the latest R-Devel code.
Testing your package with R-Devel
The next logical step is to test your package or more generally to use your package with the R-Devel version in a Docker container.
Let’s assume you have put your package in a folder named mypackage
in your home folder (~/mypackage
). To link this folder with a Docker container, the parameter -v ~/mypackage:/RPackage/mypackage
can be provided when executing docker run
. The folder /RPackage/mypackage
inside the Docker container will then be linked with the ~/mypackage
folder on your host system.
To start a Docker container with the built Docker image and to be able to access your package dir, run the following command:
|
|
Next, you can check the R-Devel version:
|
|
Note that RD
starts the devel version of R (instead of R
).
Often it is necessary to install system dependencies and other dependent R packages before you can test your package.
For example, the following dependencies are necessary to build pdf vignette files (e.g. for my parallelDist package):
|
|
You can also install all necessary dependencies for your package with one command:
|
|
After you have installed all necessary system dependencies and R packages, you are ready to build and test your package against the latest R-Devel version.
Just change to the /RPackage
dir, build your package and test it using the following commands:
|
|
The advantage of using a Docker container becomes obvious if the test results contain errors, warnings, or notes you have to fix. You can simply work on your package on the host system (or directly in the container) and quickly test your changes in the Docker container against the latest R version. Happy fixing & testing!