R Package Updates

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.

How to update all packages for a new R version quickly and easily?

Don't know if this is quick and easy, but I think the pacman package can be useful.

  1. Under the previous version, use pacman::p_lib() to return a vector of your installed packages, and save them onto disk use saveRDS().

For instance,

mypks <- pacman::p_lib()
saveRDS(mypks, "~/mypks.rds")

  1. Update R.

  2. Import the vector from step 1 using readRDS() and run install.packages() with the object.

For instance,

mypks <- readRDS("~/mypks.rds")
install.packages(mypks)

R package updates

Restart R and run install.packages again. On Windows, you can't update a package that's already loaded, if the package contains compiled C/C++/Fortran code. This includes dplyr and rlang.

To be doubly sure, before you run install.packages, go to your R packages directory (C:/Users/tomsp/OneDrive/Documents/R/win-library/3.5) and delete any zero-length files that are present. These are artifacts of failed install attempts and will break install.packages if present.

R schedule automatic package updates

add this to specify CRAN mirror:

options(repos = c(CRAN = "http://cran.rstudio.com"))

Does it work now?

Updating R, R packages best practices

For your programming environment, update unless you have good reason not to, and maintain a good test suite for your in-house code. For projects with special needs, use renv to control versions of packages.

For your production environment, use the renv package to keep package versions locked down, and upgrade in a controlled manner if there is an explicit need.



Related Topics



Leave a reply



Submit