Save your R packages when updating R version

This post is a copy and paste of an r-blogger article.

However, it is so useful that I keep it here to remember about the process to save and restore all R packages when updating to a newer version of R.

tmp <- installed.packages()
installedpkgs <- as.vector(tmp[[,"Priority"]), 1])
save(installedpkgs, file="installed_old.rda")
tmp <- installed.packages() <- as.vector(tmp[[,"Priority"]), 1])
missing <- setdiff(installedpkgs,