R package guidelines
32-bit – CLR – Cross – Eclipse – Electron – Free Pascal – GNOME – Go – Haskell – Java – KDE – Kernel – Lisp – MinGW – Node.js – Nonfree – OCaml – Perl – PHP – Python – R – Ruby – Rust – VCS – Web – Wine
This document covers standards and guidelines on writing PKGBUILDs for R packages. Most information can be obtained by looking at the package's DESCRIPTION file. You can get most of this from inside R by running tools::CRAN_package_db().
Contents
Package naming
Packages should be named r-pkgname, where pkgname is taken from the Package field from the DESCRIPTION file.
The package name should be lowercase.
Package Version
Take it from the Version field. R allows packages to have colons and hyphens in their version, this is disallowed in PKGBUILDs. Convert these to a period or underscore.
Arch
See PKGBUILD#arch. If the package's CRAN webpage has NeedsCompilation: yes it is likely architecture-specific. Otherwise, it is likely not.
Dependencies
R packages listed in Depends, Imports, or the LinkingTo fields in a package's DESCRIPTION file should be listed under depends.
R packages listed in Suggests should be listed as optdepends.
Some packages require external tools, these are listed under SystemRequirements.
gcc-fortran is needed as a makedepends for some packages but is not always listed in the DESCRIPTION file.
Source
All R packages available on CRAN are available at the website https://cran.r-project.org/src/contrib/cranname_cranversion.tar.gz where cranname is the name of the package on CRAN and cranversion the cran version.
Build and Package
R has built-in support for building packages, we just need to install and copy over the built package afterwards:
build(){
R CMD INSTALL pkg.tar.gz -l "$srcdir"
}
package() {
install -dm0775 "$pkgdir"/usr/lib/R/library
cp -a --no-preserve=ownership pkgname "$pkgdir"/usr/lib/R/library
}
Examples
RcppEigen
pkgname=r-rcppeigen
pkgver=0.3.3.4.0
pkgrel=1
pkgdesc="Rcpp Integration for the Eigen Templated Linear Algebra Library"
arch=('x86_64')
url="https://cran.r-project.org/package=RcppEigen"
license=('GPL')
depends=('r' 'r-rcpp')
optdepends=('r-inline' 'r-runit' 'r-pkgkitten')
source=("https://cran.r-project.org/src/contrib/RcppEigen_$pkgver.tar.gz")
md5sums=('78ee1ef7c6043efa875434ae5fcea2ec')
build(){
R CMD INSTALL RcppEigen_"$pkgver".tar.gz -l "$srcdir"
}
package() {
install -dm0755 "$pkgdir"/usr/lib/R/library
cp -a --no-preserve=ownership RcppEigen "$pkgdir"/usr/lib/R/library
}
XML
An example where the R package has characters not allowed in pkgver:
_cranver=3.98-1.11
pkgname=r-xml
pkgver=${_cranver//[:-]/.}
pkgrel=1
pkgdesc='Tools for Parsing and Generating XML Within R and S-Plus'
arch=('x86_64')
url='https://cran.r-project.org/package=XML'
license=('BSD')
depends=('r' 'libxml2')
optdepends=('r-bitops' 'r-rcurl')
replaces=('r-cran-xml')
source=("https://cran.r-project.org/src/contrib/XML_$_cranver.tar.gz")
md5sums=('6c67f5730ada3456372520773a920b8e')
build(){
R CMD INSTALL XML_"$_cranver".tar.gz -l "$srcdir"
}
package() {
install -dm0755 "$pkgdir"/usr/lib/R/library
cp -a --no-preserve=ownership XML "$pkgdir"/usr/lib/R/library
}