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.

- 105
- 8
-
I just had the same problem. – rokamama Mar 25 '21 at 15:29
-
1You could try a [manual migration](https://stackoverflow.com/questions/62353392/how-to-update-r-from-3-x-to-4-x-and-should-i/62353652#62353652) – Waldi Mar 25 '21 at 16:05
-
@Waldi Thank you! Though I'm more interested in the cause of the bug. – rokamama Mar 26 '21 at 18:44
2 Answers
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:
- get your old packages
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.

- 11,727
- 1
- 23
- 45
-
"This is because updating from R 3.6.x to 4.x requires that you reinstall all packages" Ah I see! Is it known why is that? – rokamama Mar 26 '21 at 18:42
-
Not really. I just noticed it when looking at the [official change log](https://cran.r-project.org/doc/manuals/r-devel/NEWS.html) "Packages need to be (re-)installed under this version (4.0.0) of R." – JBGruber Mar 27 '21 at 07:12
-
i had the same problem when updating version 4.0.2 to 4.1.0. I said yes to move packages from old to new version and yes to update packages. Any user package was moved from folder 4.0 to 4.1. i had to use this answer to reinstall all packages. – josep maria porrà Jul 03 '21 at 14:08
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
...

- 39,242
- 6
- 30
- 78
-
1Nice analysis of the problem. The solution will not work though, I think. The command `copy.packages.between.libraries` will use `file.copy` eventually. And as far as I read the [change log](https://cran.r-project.org/doc/manuals/r-devel/NEWS.html) (look for "CHANGES IN R 4.0.0"), the copied files will be broken/useless due to changes in `R` 4.0.0. . – JBGruber Mar 27 '21 at 07:19
-
1@JBGruber, in comments to the post OP is actually interested in the cause of the bug. If `copy.packages.beween.libraries`doesn't work `install.packages` will do. – Waldi Mar 27 '21 at 07:24
-
@JBGruber, thanks for you comment on `file.copy` in `copy.between.packegs` : I remove the last workaround, you're right it won't work. – Waldi Mar 27 '21 at 07:36