简体   繁体   中英

r update.packages() not updating packages that are imported by other packages

I recently updated to R 3.5.1 from 3.4.3. I updated my packages as follows:

(a) copied packages from my old library into my new library (taking care not to overwrite the base packages)

(b) ran update.packages(ask = FALSE, dependencies = TRUE)

I found that a number of packages didn't install where they were listed as imports of other packages as they had 'been created with an r version with different internals, and needs to be reinstalled'.

Somewhat frustratingly, this message seemed to be iterating through some hidden list of associated or linked packages but only telling me there was a problem for one package at a time; ie I would install the package that had the wrong version, then try reinstalling the package it had blocked from installing, only to get the error repeated for a different package. I had to go through this multiple times until there were no more incorrect-version associated packages and finally the package I needed to use could be installed / updated.

Also - I note that some packages were installed from source (these were frequently but not exclusively the ones that caused the 'different internals' error for associated packages above). I do have Rtools installed so not a problem for me but just an observation as update.packages was doing this every time it encountered a source version that was more up to date than a windows binary (I have a windows 10 PC).

I conclude from all this that update.packages skipped a lot of packages and did not in fact update them for some reason? I'm still finding packages that did not update.

For example:

> DescTools::Gmean(x)
Error: package ‘expm’ was installed by an R version with different internals; it needs to be reinstalled for use with this R version

Looking at the CRAN entry for DescTools here indicates that the package expm is not a dependency but is imported.

However ?import.packages says of the dependencies argument:

dependencies:

logical indicating whether to also install uninstalled packages which these packages depend on/link to/import/suggest (and so on recursively). Not used if repos = NULL. Can also be a character vector, a subset of c("Depends", "Imports", "LinkingTo", "Suggests", "Enhances").

Only supported if lib is of length one (or missing), so it is unambiguous where to install the dependent packages. If this is not the case it is ignored, with a warning.

The default, NA, means c("Depends", "Imports", "LinkingTo"). TRUE means to use c("Depends", "Imports", "LinkingTo", "Suggests") for pkgs and c("Depends", "Imports", "LinkingTo") for added dependencies: this installs all the packages needed to run pkgs, their examples, tests and vignettes (if the package author specified them correctly).

In all of these, "LinkingTo" is omitted for binary packages.

This implies that update.packages(...dependencies = TRUE) should have also updated and / or installed all packages imported by other packages as well.

What am I missing?

I had the same issue after update to R 3.6.0. In my case a slight modification of Carlos Santillan's solution solved the problem:

for (i in 2:length(.libPaths())) {
  lib <- .libPaths()[i]
  install.packages( 
    lib  = .libPaths()[1] ,
    pkgs = as.data.frame(installed.packages(lib), stringsAsFactors=FALSE)$Package,
    type = 'source'
  )
}

In my setup .libPaths() retuns the following:

> .libPaths()
[1] "/home/wassermann/R/x86_64-pc-linux-gnu-library/3.6" "/usr/local/lib/R/site-library"                
[3] "/usr/lib/R/site-library"                            "/usr/lib/R/library"    

The first directory in .libPaths() is writeable at the user level, the other three are read-only. The code iterates over all packages in read-only folders and installs their newer versions in the user writeable directory. It's not optimal in the sense that it may iterate over some packages more than once, but you need to run it only once and after that all packages install without the iritating "different internals" error.

It looks like dependencies = TRUE is not a parameter for update.packages instead it passes it parameter to the install.packages

The documentation

https://www.rdocumentation.org/packages/utils/versions/3.5.1/topics/update.packages

says

Take care when using dependencies (passed to install.packages) with update.packages, for it is unclear where new dependencies should be installed. The current implementation will only allow it if all the packages to be updated are in a single library, when that library will be used.

The following script will reinstall all packages

lib <- .libPaths()[1]
install.packages( 
    lib  = lib ,
    pkgs = as.data.frame(installed.packages(lib), stringsAsFactors=FALSE)$Package,
    type = 'source'
)

The following will update check if all packages need updating

lib <- .libPaths()[1]
update.packages( 
 oldPkgs = as.data.frame(installed.packages(lib), stringsAsFactors=FALSE)$Package,
  type = 'source',
  ask = FALSE
)

(above was modified from https://www.r-bloggers.com/update-all-user-installed-r-packages-again/ )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM