updating package in R: `update.packages` vs. `install.packages`

r

Solution

This is yet another reason why I prefer to launch both the "install" and "update" operations outside of my current, working R session.

By using the command-line, I get fresh R sessions without loaded packages, and the issue you experienced here does not arise. And as a shortcut, I define scripts `update.r` and `install.r` using littler (and included in the `examples/` directory of that package) but you can of course do the same via Rscript.

Problem

I've tried to load the `party` library and got the following error: ``` Loading required package: zoo Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : namespace ‘lattice’ 0.20-24 is already loaded, but >= 0.20.27 is required Error: package ‘zoo’ could not be loaded ``` So I decided to update all packages within the same session (detach all packages while working in R), including `lattice`, hoping that `zoo` and then `party` would then load correctly once `lattice` is updated: ``` pkgs <- names( sessionInfo()$otherPkgs ) pkgs <- paste('package:', pkgs, sep = "") lapply( pkgs , detach, character.only = TRUE, unload = TRUE) update.packages(checkBuilt=TRUE, ask=FALSE, repos="http://r-forge.r-project.org", oldPkgs=c("lattice","zoo","party") ) ``` It didn't work (within the same session and after re-starting without preloading `.RData`): ``` > library(party) Loading required package: zoo Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : namespace ‘lattice’ 0.20-24 is already loaded, but >= 0.20.27 is required Error: package ‘zoo’ could not be loaded ``` According to How to update R2jags in R? it's best to simply run `install.packages` on those packages I want to update, then restart. And indeed it did the trick. So here's the question: when is `update.packages` called for, given that updating within a running session is fragile to say the least, and `install.package` will do the trick at the cost of restarting the session? What bit of `R` package management voodoo am I missing? Thanks.

Original source

Related problems