How to update a package in R?

You can’t do this I’m afraid, well, not with update.packages(). You need to call install.packages("R2jags") instead.

You can’t install R2jags in the current session because you have already loaded the current version into the session. If you need to, save any objects you can’t easily recreate, and quit out of R. Then start a new R session, immediately run install.packages("R2jags"), then once finished, load the package and reload in any previously saved objects. You could try to unload the package with:

detach(package:R2jags, unload = TRUE)

but it is quite complex to do this cleanly unless the package cleans up after itself.

update.packages() exists to update all outdated packages in a stated library location. That library location is given by the first argument (if not supplied it works on all known library locations for the current R session). Hence you were asking it the update the packages in library location R2jags which is most unlikely to exist on your R installation.

Leave a Comment