On Windows, we have a package called installr. Use function copy.packages.between.libraries(), then problem solved.

On macOS, unfortunately, we don’t have that handy tool.

But we can still use the following to retrieve all current installed packages’ names:

to_install <- as.vector(installed.packages()[,1])

A more concrete solution would be only updating those non-base-R packages:

installed <- as.data.frame(installed.packages())
write.csv(installed, 'installed_previously.csv')

installedPreviously <- read.csv('installed_previously.csv')
baseR <- as.data.frame(installed.packages())
toInstall <- setdiff(installedPreviously, baseR)


Still, I wish those old packages can be transferred to a new version of R painlessly.