Created
June 11, 2021 13:20
-
-
Save pja237/3856b58d370e34850a031897322c7616 to your computer and use it in GitHub Desktop.
Migrating packages between R installations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Open old version of R and type: | |
packages.file <- "Rpackages.RData" | |
a <- installed.packages() | |
my.packages <- a[,"Package"] | |
save(my.packages, file = packages.file) | |
### Open new version of R and type: | |
packages.file <- "Rpackages.RData" | |
load(packages.file) # my.packages | |
new.packages <- installed.packages() | |
new.packages <- new.packages[,"Package"] | |
need.to.install <- my.packages[!(my.packages %in% new.packages)] | |
# Install packages from CRAN | |
# you might be prompted that you don't have the permissions to install into the default (admin) library and asked whether you want to install the packages into your local library instead --> confirm with yes | |
install.packages(pkgs = unique(need.to.install), repos = "http://cran.r-project.org") | |
# Some packages will not be found because they are from Bioconductor | |
# Install remaining packages from Bioconductor: | |
new.packages <- installed.packages() | |
new.packages <- new.packages[,"Package"] | |
need.to.install <- my.packages[!(my.packages %in% new.packages)] | |
if (!requireNamespace("BiocManager", quietly = TRUE)){ | |
install.packages("BiocManager") | |
} | |
BiocManager::install(unique(need.to.install)) | |
# Some packages might still not be installed because they are not available for the new version of R, their dependency is not available, or something went wrong during the installation | |
# Check which packages were not installed | |
new.packages <- installed.packages() | |
new.packages <- new.packages[,"Package"] | |
not.installed <- my.packages[!(my.packages %in% new.packages)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment