What determines CRAN binary compatibility?

Viewed 39

CRAN has binary versions of packages for Windows and macOS. However, install.packages() will only use these when running in the official CRAN R distribution. If one uses a different R distribution (e.g. from Homebrew or MacPorts on macOS) or compiles R from sources oneself, then install.packages() will not download binaries and will instead compile all packages from sources.

Questions:

  • Why does install.packages() refuse to get binaries from CRAN when running in a non-official R distribution? I assume there is some concern about binary compatibility, and I am looking to gain some technical insight into the reason for that.
  • How is binary compatibility verified? How does install.packages() tell whether binaries can be used or not?
  • What is required to produce a separate R distribution that is (a) compatible with CRAN binaries (b) will be detected as compatible by install.packages()?
1 Answers

From the docs in ?install.packages regarding the type parameter:

Possible values of type are (currently) "source", "mac.binary", and "win.binary": the appropriate binary type where supported can also be selected as "binary".

The default setting for type is getOption("pkgType"). This option seems to be defaulted to "source" in non-CRAN builds, and if you try to set the option to "both", (which would be the default on CRAN builds), then install.packages will complain. You could set the option to "mac.binary", or bypass the options altogether by using the type parameter.

So, to install the latest MacOS binary for, say, dplyr, you could do:

install.packages("dplyr", type = "mac.binary")

or

options(pkgType = "mac.binary")

install.packages("dplyr")

Note this will also install the dependencies of the installed package.

Related