4

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.

Community
  • 1
  • 1
user2105469
  • 1,413
  • 3
  • 20
  • 37

2 Answers2

10

Dirk offers a more general strategy to avoid this issue. However, if you are in an interactive session that you don't feel like rebooting, and you want to unload a package that needs updating (which neither detach(.)-ing orupdate.packages(.)-ing effectively accomplishes), then there is a function, unloadNamespace that usually works for me. There are warnings in its help page that say it's not entirely safe, but I have not had difficulties. Try:

unloadNamespace("lattice")   # or lapply()-ing as you attempted with `detach`
update.packages("lattice")
require(lattice)  # or library()
IRTFM
  • 258,963
  • 21
  • 364
  • 487
7

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.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725