Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

r

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.

like image 671
user2105469 Avatar asked Dec 02 '22 19:12

user2105469


1 Answers

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()
like image 50
IRTFM Avatar answered Dec 25 '22 06:12

IRTFM