Tomas
Tomas

Reputation: 59575

How to update a package in 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".

Upvotes: 57

Views: 149639

Answers (4)

Gavin Simpson
Gavin Simpson

Reputation: 174938

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)

(yes, unquoted names are accepted as first argument, ?detach) 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.

Upvotes: 50

M4RT1NK4
M4RT1NK4

Reputation: 503

update.packages(oldPkgs = "R2jags") will check updates only for that package and ask you if you want to update.

Upvotes: 7

DJ6968
DJ6968

Reputation: 109

# The following two commands remove any previously installed H2O packages for R.
if ("package:h2o" %in% search()) { detach("package:h2o", unload=TRUE) }
if ("h2o" %in% rownames(installed.packages())) { remove.packages("h2o") }

# Next, we download packages that H2O depends on.
pkgs <- c("RCurl","jsonlite")
for (pkg in pkgs) {
if (! (pkg %in% rownames(installed.packages()))) { install.packages(pkg) }
}

# Now we download, install and initialize the H2O package for R.
install.packages("h2o", type="source", repos="http://h2o-release.s3.amazonaws.com/h2o/rel-xia/2/R")

# Finally, let's load H2O and start up an H2O cluster
library(h2o)`enter code here`
h2o.init()

Upvotes: 0

americo
americo

Reputation: 1063

Additionally, you can install RStudio and update all packages by going to the Tools menu and selecting Check for Package Updates.

Upvotes: 32

Related Questions