How to Upgrade R Without Losing Your Packages (2024)

Posted on June 19, 2015 by Kris Eberwein in R bloggers | 0 Comments

[This article was first published on R Tricks – Data Science Riot!, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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.

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

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

source("*te.R")chooseBioCmirror()biocl*te()load("installed_old.rda")tmp <- installed.packages() <- as.vector(tmp[[,"Priority"]), 1])missing <- setdiff(installedpkgs, (i in 1:length(missing)) biocl*te(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!

How to Upgrade R Without Losing Your Packages (1)


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 about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

How to Upgrade R Without Losing Your Packages (2024)
Top Articles
Latest Posts
Article information

Author: Greg Kuvalis

Last Updated:

Views: 6178

Rating: 4.4 / 5 (75 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Greg Kuvalis

Birthday: 1996-12-20

Address: 53157 Trantow Inlet, Townemouth, FL 92564-0267

Phone: +68218650356656

Job: IT Representative

Hobby: Knitting, Amateur radio, Skiing, Running, Mountain biking, Slacklining, Electronics

Introduction: My name is Greg Kuvalis, I am a witty, spotless, beautiful, charming, delightful, thankful, beautiful person who loves writing and wants to share my knowledge and understanding with you.