Robert's Data Science Blog

Package X Was Built Under R Version Y

This is a problem that can easily pop up in R on Windows or Mac (here with my example R package arithmetic1):

> library(arithmetic1)
Warning message:
package ‘arithmetic1’ was built under R version 3.6.1

It usually happens if I use a version of R that is not the bleeding edge, yet install packages from the usual CRAN (https://cloud.r-project.org).

I was curious to know how R determines that the R version attaching the package and the version used to make the binary build are out of sync.

I ended up in the source code of the library function.

Somewhere in the library function, metadata about the package is found in this manner:

pkgInfo <- readRDS(file.path(find.package("arithmetic1"), "Meta", "package.rds"))

One entry in the list pkgInfo contains information about the system that built the package:

> pkgInfo$Built
$R
[1] ‘3.6.1$Platform
[1] ""

$Date
[1] "2020-04-25 19:12:29 UTC"

$OStype
[1] "unix"

Inside R information about its version is available with the function getRversion(). So library compares pkgInfo$Built$R with getRversion().

How to replicate this?

In order to replicate the error message without installing from CRAN we should have two versions of R installed. Here I use a Linux machine, but the same can be achieved with e.g. PowerShell on Windows. I write out the full path to R to ensure that I use the desired versions.

With the newest version of R I create a binary version of the package:

$ /opt/R/3.6.1/bin/R CMD INSTALL --build arithmetic1
* installing to library ‘/home/robert/R/x86_64-pc-linux-gnu-library/3.6.1’
* installing *source* package ‘arithmetic1’ ...
** using staged installation
** R
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* creating tarball
packaged installation of ‘arithmetic1’ as ‘arithmetic1_0.0.1_R_x86_64-pc-linux-gnu.tar.gz’
* DONE (arithmetic1)

I install the binary version of the package in the old version of R:

$ /opt/R/3.6.0/bin/R CMD INSTALL arithmetic1_0.0.1_R_x86_64-pc-linux-gnu.tar.gz
WARNING: ignoring environment value of R_HOME
* installing to library ‘/home/robert/R/x86_64-pc-linux-gnu-library/3.6.0’
* installing *binary* package ‘arithmetic1’ ...
* DONE (arithmetic1)

I now start the old version of R and attach the package.

> library(arithmetic1)
Warning message:
package ‘arithmetic1’ was built under R version 3.6.1