Hints for building GNU R packages

This page assembles some hints about GNU R packages.

An upstream R package FooBar in CRAN can be packaged as the debian package r-cran-foobar (or r-bioc-foobar for a package in Bioconductor). Note the change of case (debian package names are all-lowercase).

Debian-packaged R libraries are installed into /usr/lib/R/site-library. They can be imported and used as normal in R (library("FooBar")), except that they are read-only, and hence cannot be updated by the user using R's built-in mechanisms.

Libraries installed in a user's home directory will take precedence over debian-packaged libraries in site-library by default.

Debhelper packaging

`dh-make-R`

The package dh-r provides a debhelper module for building R packages, and a utility script dh-make-R to generate a skeleton debian/ directory, when run from within an unpacked R package tarball.

Options:

If packaging files like debian/control already exist, dh-make-R will not overwrite them.

At a minimum, you'll need to manually edit debian/copyright after running dh-make-R. If the package has non-R dependencies (eg, system libraries), you'll need to add them manually in debian/control.

`dh-r`

dh-r provides a debhelper buildsystem for R packages. To use it, the package needs to build-depend on dh-r, and debian/rules should look like:

 #!/usr/bin/make -f
 
 %:
     dh $@ --buildsystem R  

dh-r generates substitution variables for R dependencies, so your binary package stanza in debian/control should use ${R:Depends}, ${R:Recommends} and ${R:Suggests}. These will be generated at build-time based on the available package list (warnings will be shown for R package names which do not appear to have a corresponding debian package).

Optionally, you can attempt to generate the vignette during build, by adding --with vignette to the dh $@ line. Note that you'll need to add explicit build-depends on whatever is compiling the documentation (eg, texlive). Providing an installed vignette has generally not been required for R packages in debian.

Specifics of GNU R packages

RData files (*.rda) in source packages

It seems to be a frequently discussed topic between R package maintainers and ftpmaster that several R packages are containing RData files which somehow are looking like binary files without source for people not familiar with R. However, for people who are working with R this is a non-issue because these so called serialized R objects can be input and manipulated in R by humans, I guess in the same way that png files can be edited using image manipulation programs.

There is some decision on R datasets from ftpmaster that adds some requirements the maintainer needs to check in case the upstream source contains RDate files.

Relevant hint: Since GNU R upstream sources are usually quite good documented in very many cases the according RData files are documented inside the docs. It is a very good idea to grep for the file name of the files and check the according hits whether all questions you need to answer are just answered there.

Usage of the ${R:Depends} variable

In 659163 the ${R:Depends} variable was used to simplify the versioned dependency in R packages. It seems that the current implementation which contains a hardcoded dependency to the version of the r-base-dev package:

dpkg-query -W -f='$${Version}' r-base-dev

under some circumstances creates to strict dependencies which in turn requires a rebuild of packages that could be avoided if the variable would simply regard an R API version like it was originally suggested:

R --version | head -n1 | perl -ne 'print / +([0-9]\.[0-9]+\.[0-9])/'

In dh-r, ${R:Depends} will include both a dependency on R and any R packages listed in DESCRIPTION as dependencies.