I recently used the installr package to update my version of R (from 3.6.2 to 4.0.0). The update was successful, and I have confirmed using print(R.version)
. However, my packages from the old version of R have not copied over to the new version, despite me following these steps to the letter. I have also tried to run copy.packages.between.libraries(ask = T)
to copy the packages over. Both times returned No packages to copy. Goodbye :)
, despite me being unable to load any of the packages previously installed on the old version.
Upgrade R to a new version-and copy all of the packages from the old R installation to the new one. Move to a global library system-and wanting to copy all of packages from the local library folder to the global one.
Upgrade R Without Losing Your Packages 1. Before you upgrade, build a temp file with all of your old packages. tmp <- installed.packages() installedpkgs <- as. 2. Install the new version of R and let it do it’s thing. 3. Once you’ve got the new version up and running, reload the saved packages and ...
Before you upgrade, build a temp file with all of your old packages. 2. Install the new version of R and let it do it’s thing. 3. Once you’ve got the new version up and running, reload the saved packages and re-install them from CRAN.
"On most single-user systems (Mac, Windows, and Linux), when you upgrade to a new minor version of R (like 3.3.0 to 3.4.0), R will not find the packages, you will need to reinstall your R packages. This is an inconvenience, but the problem is obvious and it is easy to fix.
This is because updating from R 3.6.x to 4.x requires that you reinstall all packages (see the news).
The best way I found of doing this is:
old_packages <- installed.packages(lib.loc = "/home/johannes/R/x86_64-pc-linux-gnu-library/3.6/")
Of course, you have to change the path to the one where your packages live. Simply use .libPaths()
and if you've already installed the new R version, replace the 4.0
with 3.6
.
check the old against the already installed packages:
new_packages <- installed.packages()
missing_df <- as.data.frame(old_packages[
!old_packages[, "Package"] %in% new_packages[, "Package"],
])
install missing packages (use multiple cores for extra speed)
install.packages(missing_df$Package, Ncpus = 3)
I wrote this up on my blog some time ago here, but these are the essential steps and you should be good to go.
If you have a look at the source code of copy.packages.between.libraries
(just type F2
when your mouse pointer is on the function name), you find the following commands :
library(installr)
(installed_R_folders <- get.installed.R.folders())
#> 4.0.3 4.0.2
#> "C:/PROGRA~1/R/R-4.0.3" "C:/PROGRA~1/R/R-4.0.2"
(installed_R_folders_TABLE <- data.frame(R_version = names(installed_R_folders),
Folder = installed_R_folders))
#> R_version Folder
#> 4.0.3 4.0.3 C:/PROGRA~1/R/R-4.0.3
#> 4.0.2 4.0.2 C:/PROGRA~1/R/R-4.0.2
(from <- installed_R_folders[2])
#> 4.0.2
#> "C:/PROGRA~1/R/R-4.0.2"
(to <- installed_R_folders[1])
#> 4.0.3
#> "C:/PROGRA~1/R/R-4.0.3"
(from_library <- file.path(from, "library"))
#> [1] "C:/PROGRA~1/R/R-4.0.2/library"
(to_library <- file.path(to, "library"))
#> [1] "C:/PROGRA~1/R/R-4.0.3/library"
(packages_in_the_from_library <- list.files(from_library))
#> [1] "base" "boot" "class" "cluster" "codetools"
#> [6] "compiler" "datasets" "foreign" "graphics" "grDevices"
#> [11] "grid" "KernSmooth" "lattice" "MASS" "Matrix"
#> [16] "methods" "mgcv" "nlme" "nnet" "parallel"
#> [21] "rpart" "spatial" "splines" "stats" "stats4"
#> [26] "survival" "tcltk" "tools" "translations" "utils"
(packages_in_the_to_library <- list.files(to_library))
#> [1] "base" "boot" "class" "cluster" "codetools"
#> [6] "compiler" "datasets" "foreign" "graphics" "grDevices"
#> [11] "grid" "KernSmooth" "lattice" "MASS" "Matrix"
#> [16] "methods" "mgcv" "nlme" "nnet" "parallel"
#> [21] "rpart" "spatial" "splines" "stats" "stats4"
#> [26] "survival" "tcltk" "tools" "translations" "utils"
(packages_to_NOT_move <- unname(installed.packages(priority = "high")[,"Package"]))
#> [1] "codetools" "base" "boot" "class" "cluster"
#> [6] "codetools" "compiler" "datasets" "foreign" "graphics"
#> [11] "grDevices" "grid" "KernSmooth" "lattice" "MASS"
#> [16] "Matrix" "methods" "mgcv" "nlme" "nnet"
#> [21] "parallel" "rpart" "spatial" "splines" "stats"
#> [26] "stats4" "survival" "tcltk" "tools" "utils"
(packages_to_NOT_move <- c(packages_to_NOT_move, packages_in_the_to_library))
#> [1] "codetools" "base" "boot" "class" "cluster"
#> [6] "codetools" "compiler" "datasets" "foreign" "graphics"
#> [11] "grDevices" "grid" "KernSmooth" "lattice" "MASS"
#> [16] "Matrix" "methods" "mgcv" "nlme" "nnet"
#> [21] "parallel" "rpart" "spatial" "splines" "stats"
#> [26] "stats4" "survival" "tcltk" "tools" "utils"
#> [31] "base" "boot" "class" "cluster" "codetools"
#> [36] "compiler" "datasets" "foreign" "graphics" "grDevices"
#> [41] "grid" "KernSmooth" "lattice" "MASS" "Matrix"
#> [46] "methods" "mgcv" "nlme" "nnet" "parallel"
#> [51] "rpart" "spatial" "splines" "stats" "stats4"
#> [56] "survival" "tcltk" "tools" "translations" "utils"
(ss_packages_to_NOT_move_from <- packages_in_the_from_library %in%
packages_to_NOT_move)
#> [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
#> [16] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
(ss_packages_to_YES_move_from <- !ss_packages_to_NOT_move_from)
#> [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
#> [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
#> [25] FALSE FALSE FALSE FALSE FALSE FALSE
(packages_to_YES_move_from <- packages_in_the_from_library[ss_packages_to_YES_move_from])
#> character(0)
Which comes to the conclusion there's no difference between the packages of the different R installations and leads to:
No packages to copy. Goodbye :)
However, if you look at .libPaths()
, you see that get.installed.R.folders
is missing the packages you installed on your own user's library:
.libPaths()
[1] "C:/Users/User/Documents/R/win-library/4.0"
[2] "C:/Program Files/R/R-4.0.3/library"
So default behaviour of installr
is missing all the packages you installed after R installation :
packages <- as.data.frame(utils::installed.packages())
head(packages[is.na(packages$Priority),c("Package","LibPath")])
arrow arrow C:/Users/User/Documents/R/win-library/4.0
arules arules C:/Users/User/Documents/R/win-library/4.0
arulesViz arulesViz C:/User/User/Documents/R/win-library/4.0
ash ash C:/Users/User/Documents/R/win-library/4.0
askpass askpass C:/Users/User/Documents/R/win-library/4.0
assertive assertive C:/Users/User/Documents/R/win-library/4.0
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With