Warning message: package ‘x’ was built under R version 'y'

R

2 February, 2022



Introduction

Warning message: package 'x' was built under R version 'y' is a pretty common warning to see. It's usually not something to worry about, but what does it mean?

Package binaries vs source

The package structure and state chapter from R Packages describes in detail the different states of R packages (from source to binary to installed to in-memory)—I'll just summarise the general vibe of the thing here.

The source code for R packages is basically just a bunch of files. Those files probably contain some functions, maybe some data, some documentation, and so on... but they're really just a bunch of files. When installing a package, however, you'll probably be downloading a package bundle or binary. These are both single files containing all the essential parts of your package. There are some differences—binaries are platform-specific whereas bundles aren't—but they both represent an intermediate state of the package, somewhere between source code and installed package.

The important thing to note here is that CRAN (and other package repositories) builds package binaries under the latest patch version of R, for a given major/minor version. This means that a package installed from a binary might be built under a different version of R than what you are running, and that's what's triggering the error.

R versions

What does that mean, exactly? Well, let's look at R 4.1.2. The major version of R is 4; the minor version in 1; and the patch version is 2. Features are introduced in major and minor version updates; patch versions of R typically contain bug fixes. If you're running a version of R that isn't the latest—e.g., 4.1.0—then packages that you install may have been built under R 4.1.2, rather than R 4.1.0.

Is this a problem? Well, probably not. Since patch versions of R mainly contain bug fixes (rather than new features which may have a higher probability of introducing bugs or changing code behaviour), it's unlikely that building packages under a slightly newer version of R will introduce breaking changes. (This is why it's a warning, rather than an error, right—something to keep in mind, but not necessarily worry about.)

Build from source

One way to avoid this error is to build and install packages from source (or from the package bundle). You're most likely to use devtools to do this, which is ultimately calling the command-line function R CMD INSTALL in the background. Installing a package converts the source code (or bundle, or binary) into a package library, which is the collection of files you see in your R library in the filesystem.

Now, this is going to be different depending on whether you're on Windows or a Unix-alike. On Linux, for example, running the standard install.packages() will look on CRAN for the source or bundle version of the package, not the binary version. Windows, on the other hand, will first look for a binary version (and only install from source if no appropriate binary is found).

Anyway, I'm on a Linux box so if I run install.packages("cronR"), it'll install the latest version of cronR on CRAN from source. This means that it will build and compile all the code locally—under my currently installed version of R. By definition, then, if you build the package from source, you won't see the warning.

Finally, we can reproduce the error by intentionally building from a package binary. On Linux, we have to be specific about this, so I'm installing it from the RStudio Public Package Manager, which provides precompiled binaries for Linux. In this example, it turns out that the binary that RStudio has built for cronR was built under R 4.0.5 (the latest patch version), rather than the 4.0.4 that's installed—hence the warning message.

Why would we ever install a package from a binary, then?

It's faster :)

References



0 comments

Leave a comment