pak icon indicating copy to clipboard operation
pak copied to clipboard

Give warnings when library contains packages built with a different major or minor version of R

Open wch opened this issue 6 years ago • 2 comments

There are many strange bugs that can happen when you load a package built on a different major or minor version of R. We've spent a lot of time remotely debugging these problems for users and eventually I wrote an article about it. http://shiny.rstudio.com/articles/upgrade-R.html

It would be best if library() would automatically warn when loading a package like this, but we can't change that directly, so pkgman seems like a reasonable place to do this check. If you think this should go elsewhere, please let me know.

cc: @schloerke, @alandipert, @tmastny. (Today this group spent hours tracking down a crash that was probably due packages built on an old version of R.)

wch avatar Jun 26 '18 21:06 wch

Hm, it looks like this might have already been address in R. In R 3.5.0, I tried loading a package built on R 3.4.4 and got this message:

d> library(httpuv)
Error: package or namespace load failed for ‘httpuv’:
 package ‘httpuv’ was installed by an R version with different internals; it needs to be reinstalled for use with this R version

In the R sources, that check is here: https://github.com/wch/r-source/blob/507271ce/src/library/base/R/namespace.R#L454-L477

It is applied to packages that have NeedsCompilation: yes. It looks like this check was originally added two years ago, in wch/r-source@a933394690cdf661409334c15096324b14bbcbed, and was moved around since then.

wch avatar Jun 27 '18 05:06 wch

This is not a general check however. The ABI for R 3.5 differs than than of earlier versions (mainly due to changes to better support the new Altrep framework). Earlier versions will (such as from 3.3 to 3.4) will not have this error.

However library() does give you a message when you load a package compiled with a newer version of R.

Warning: package ‘Rcpp’ was built under R version 3.4.4

Anyway, one of the plans for pkgman is to have a lib_check()(https://github.com/r-lib/pkgman/issues/3) function, which would verify your library is consistent (e.g. same R package version) and other things; so we will definitely check for this there.

jimhester avatar Jun 27 '18 13:06 jimhester