Skip to content
New course: Interactive Dashboards with Shiny. Get 50% off with coupon SHINYLAUNCH.
R for the Rest of Us Logo

How to Keep Your R Packages Up to Date

David Keyes David Keyes
September 8th, 2020

A user who recently completed my Getting Started with R course sent me an email to ask a common question for those starting out with R:

How do you keep your R software up to date? As far as I know, there are no automatic updates for R, RStudio and packages. And as updates are quite frequent, it is quite a hassle to check every few weeks (or even days) if there are new versions available.

This is the kind of thing that experienced R users have often internalized to the point that they often forget to articulate the steps to newcomers. It's perhaps not surprising: unlike other pieces of software, the process of updating RStudio, R, and R packages, and it is not straightforward. So, let's take each of these in turn.

How to Update RStudio

You can update RStudio by visiting the download page on the RStudio website. Find the latest version for your operating system, download it, install it, and it will overwrite your current version.

Some people enjoy running the RStudio “dailies”, which are daily compilations of the latest code for RStudio. While a big warning says they may not be stable, they show what the RStudio team is working on. People are currently very excited to see rainbow parentheses coming in a future release of RStudio (in addition to being pretty, this makes it much easier to match open and close parentheses).

HAPPY FRIDAY! The @rstudio daily build has 🌈rainbow parentheses!!!! 😍🙌👏🥳🎉🎊 pic.twitter.com/HrgGEaH1SO

— Lucy D’Agostino McGowan (@LucyStats) July 24, 2020

How to Update R

The easiest way to update R is to simply download the newest version. Install that, and it will overwrite your current version. There are also packages to do the updating: updateR for Mac, and installr for Windows. No matter which method you use, for most people, the challenge comes not in updating R, but in what comes as a result.

How to Update R Packages

When you update R, the biggest challenge is that your personal library of packages no longer works. When I upgraded to R 4.0, all of the packages I had downloaded while using version 3.61 were no longer recognized. There are multiple approaches to dealing with this:

Some people suggest copying your old personal library to a new location and ensuring that the new version of R recognizes it

Indeed, others, including Jeff Newmiller, suggest this approach is problematic. As Jeff wrote me via email:

[Copying your library to a new location] is NOT a safe thing to do, since the whole reason R sets up a new library is to avoid mixing incompatible packages. Following the copy with a rebuild only fixes packages that are in your repository list for the new version of R... any packages that have already failed compatibility testing will remain broken, and they are the ones you are most at risk from.

Others point you to the updateR and installr packages, which each have functions to copy your existing packages to your new version of R.

Colin Gillespie and Robin Lovelace have a chapter on keeping everything up to date in their book Efficient R Programming. And Chapter 8 of Jenny Bryan and Jim Hester's What They Forgot to Teach You About R has something similar.

What Do I Do?

I may have strayed from the original question a bit because the user was asking how I handle updating my tools. Here’s my approach:

I upgrade RStudio whenever I hear about something new and exciting in the most recent version (you better believe I’m excited about rainbow parentheses).

I update R several weeks after a new version is released. I don’t like to be a guinea pig in case there are issues so I let others find them and update once they’re fixed.

I update packages quite often (probably every few days). Mostly this happens because I am asked if I want to do so when using the install_github() function from the remotes package to install a package that is not on CRAN but is on GitHub.

The prompt to update my R packages

If I don't update packages through this function, I use the packages tab in RStudio. I click the update button, which shows me which packages need updating, and then update them all.

The Downsides of Updating

Updating RStudio, R, and your packages is, for the most part, painless once you know what to do. But there are some downsides to keep in mind. In addition to having to jump through some hoops to use your old packages on a new install of R, updating R packages can also mess up some of your old code. To be clear, this doesn’t happen often as developers try their hardest to avoid breaking changes. But, at times, the development of improved packages leads to versions of code that rely on older versions of packages to break.

Fortunately, there is a solution for this: the renv package. Although I haven’t used this package myself, it looks quite helpful. It essentially keeps copies of your R packages as they existed when you wrote your original code. So, if you were using dplyr 0.8.5 to write code for analysis in March 2020, you don’t have to worry that changes made to that package in the future will make your code unusable today if you’ve updated to dplyr 1.0.

Conclusion

Keeping RStudio, R, and your packages up to date can seem like a pain, but once you know how to do it, it’s not that challenging. With packages in particular, the benefits of updating are significant: you get access to the latest functions to make your life easier. For example, many have found the addition of pivoting functions in a recent version of the tidyr package has been a drastic improvement in my R experience.

Work with R long enough and eventually you'll find that you've become an experienced user with always up to date packages. Knowing that you've got the most up-to-date tools means you can put your focus where it should be: on using R to do amazing work!

Let us know what you think by adding a comment below.

You need to be signed-in to comment on this post. Login.