How to Upgrade R Without Losing Your Packages

June 19, 2015

(This article was first published on R Tricks – Data Science Riot!, and kindly contributed to R-bloggers)

Yup kids, it’s that time again. The new version of R was just released. In the past I’ve hesitated to upgrade my R version because I knew I would lose all of my packages during the new install, which makes me very grumpy.

I found this neat little trick to save my current packages before the new install and re-load them into the new version. I did this on Mac Yosemite but I this should work on Windows or Linux as well.

1. Before you upgrade, build a temp file with all of your old packages.

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

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.

tmp <- installed.packages() <- as.vector(tmp[[,"Priority"]), 1])
missing <- setdiff(installedpkgs,

Note: If you had any packages from BioConductor, you can update those too!

tmp <- installed.packages() <- as.vector(tmp[[,"Priority"]), 1])
missing <- setdiff(installedpkgs,
for (i in 1:length(missing)) biocLite(missing[i])

All done, now you can get back to cracking out R code. This method helped me save a lot of time, hope someone else finds it useful!

To leave a comment for the author, please follow the link and comment on their blog: R Tricks – Data Science Riot!. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)