Suppose I have R version 3.x.x installed, and I upgrade to version 4.x.x, is there any quick/easy way to install all the new versions of the libraries I had installed?
Please assume all the packages are on CRAN
Suppose I have R version 3.x.x installed, and I upgrade to version 4.x.x, is there any quick/easy way to install all the new versions of the libraries I had installed?
Please assume all the packages are on CRAN
Don't know if this is quick and easy, but I think the pacman
package can be useful.
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")
Update R.
Import the vector from step 1 using readRDS()
and run install.packages()
with the object.
For instance,
mypks <- readRDS("~/mypks.rds")
install.packages(mypks)
Following works for me:
update.packages(ask = FALSE, checkBuilt = TRUE)
Don't know if this is quick and easy, but I think the pacman
package can be useful.
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")
Update R.
Import the vector from step 1 using readRDS()
and run install.packages()
with the object.
For instance,
mypks <- readRDS("~/mypks.rds")
install.packages(mypks)
Run this in the previous R installation:
# install.packages("pacman")
library(pacman)
dput(pacman::p_lib())
Copy the output to clipboard.
Open your new R version, paste the output from the previous step in place of ***paste output here***
:
vector_of_packages <- ***paste output here***
install.packages(vector_of_packages)
Notes:
The latest versions of RStudio have an Update option next to the list of packages installed under the Packages tab.
update.packages()
as a function) and 'misleading'. –
Rounders Luckily,
update.packages(ask = FALSE, checkBuilt = TRUE)
works if you just mv
or
cd oldlibdir
tar -cf . -| (cd newdir; tar -xf -)
from the shell and then run it from the R console in the new version (usually). The problem with having to save a vector of installed R packages from within your previous version to feed to update.packages
is that automatic software package upgrades (pkg, apr, rpm
) will upgrade R before you get a chance 😄
I always pkg lock
R so it only gets upgraded when I explicitly invoke an R software upgrade.
© 2022 - 2024 — McMap. All rights reserved.
update.packages()
will always do that for you. 2) In the special case of an R major version change, you can set optioncheckBuilt=TRUE
which triggers a reinstallation even if the package did not change at CRAN but because you moved R versions. – Roundersupdate.packages()
or does it figure that out? – Chronometryhelp(update.packages())
. – Rounders