Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update a package in R?

Tags:

r

I would like to upgrade one R package to the newer version which is already available. I tried

update.packages(c("R2jags")) 

but it does nothing! No output on console, no error, nothing. I used the same syntax as for install.packages but perhaps I'm doing something wrong. I have been looking at ?update.packages but I was not been able to figure out how it works, where to specify the package(s) etc. There is no example. I also tried to update the package using install.packages to "install" it again but that says "Warning: package ‘R2jags’ is in use and will not be installed".

like image 654
Tomas Avatar asked Jan 30 '14 16:01

Tomas


1 Answers

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.

like image 65
Gavin Simpson Avatar answered Sep 21 '22 12:09

Gavin Simpson