Before uploading a package to CRAN, it has to be tested using a recent development version of R that has to be installed from source:

Please ensure that R CMD check –as-cran has been run on the tarball to be uploaded before submission. This should be done with the current version of R-devel (or if that is not possible and explained in the submission, current R-patched or the current release of R.) – CRAN Repository Policy

Note: Henrik Singmann has a (probably better) tutorial for installing R devel from source, but the last update is from 2019.

Unexpected dependencies for installing R from source

Appendix A1 “Essential programs and libraries” in “R Installation and Administration” contains requisite packages for installation from source. Interestingly, Java is necessary to build R from source:

sudo apt install openjdk-11-jdk

Some dependencies are needed to build the documentation in pdf format using Latex. The following packages are for example needed:

sudo apt install texinfo

qpdf, available via

sudo apt install qpdf

Cairo is also needed for images in vignettes, via

sudo apt install libcairo2-dev

Installing R from source

  1. Download the development version from https://cran.r-project.org/ \(\to\) R Sources
  2. Unpack the sources:
tar -xf R-devel.tar.gz
  1. Go to directory and check out the file INSTALL and doc/html/R-admin.html \(\to\) “R Installation and Administration”
cd R-devel
  1. “Recommended” packages need to be installed:
./tools/rsync-recommended
./configure 

However, just using ./configure may not work:

Unless you do not want to view graphs on-screen (or use macOS) you need ‘X11’ installed, including its headers and client libraries. For recent Fedora/RedHat distributions it means (at least) RPMs ‘libX11’, ‘libX11-devel’, ‘libXt’ and ‘libXt-devel’. On Debian/Ubuntu we recommend the meta-package ‘xorg-dev’. If you really do not want these you will need to explicitly configure R without X11, using –with-x=no. – Appendix A1 in “R Installation and Administration”

Then, we need:

./configure --with-x=no

Or:

./configure --with-readline=no --with-x=no --with-cairo

Note: As of 2023/2024 it was always sufficient for me to just use ./configure.

make
make check

Tests if the installation was successful.

  1. R can now be started using the script R in directory bin:
cd bin
./R
  1. It is also possible to install R devel on the system by using
make install

but I guess this is not recommended because this replaces the current stable installation of R. However, it is also possible to have multiple R versions at the same time.

Installing dependency packages

To test your package using R CMD check, you need to make the dependencies of your packages available to R devel. That is, install all of the packages in Imports, Depends, and Suggests.

Installing packages is actually accomplished by just using install.packages(). Packages will be installed into the directory in the R variable .Library, which was R-devel/library in my case. Thus, these packages do not mess with your normal package libraries.

Building the package using R devel

cd bin
./R CMD build "path/to/package"

Be sure to replace path/to/package by the actual path to the package on your system.

Checking the package

./R CMD check --as-cran tar-ball.tar.gz

I usually ignore the warning “‘qpdf’ is needed for checks on size reduction of PDFs” and the note “Skipping checking HTML validation: no command ‘tidy’ found”, which are not relevant for CRAN.

On Windows

Note: Save yourself some pain and just use the win builder. If you choose not to, the notes below may or may not help.

Some extra work may be required to check your package on a Windows system. Fortunately, at least, we can use R CMD build and R CMD check in the RStudio terminal. I had to get latex running so that R CMD check can build the pdf manuals. First, we have to install Miktex. After installing Miktex, a restart is required so R finds the path to Latex.

Before R CMD check worked properly, however, I had to enable some fonts as described here. Put the following in the standard Windows terminal:

initexmf --update-fndb
initexmf --edit-config-file updmap

The second command opens the text editor where we put:

Map zi4.map

Last, we type

initexmf --mkmaps

into the terminal. Then, R CMD check should work on the tar ball that can be build using the RStudio terminal via R CMD build "." (in the procect directory of the package).

I did not try to install R devel from source though on Windows, but used the released version. This seemed to be enough.


Last updated: 2024-04-24