23 How to update packages

Written by Mariam Walaa and last updated on 7 October 2021.

23.1 Introduction

In this lesson, you will learn how to:

Prerequisite skills include:

  • Being able to install packages.
  • Being able to load packages.

Highlights:

  • Update packages to avoid running into bugs or missing out on updates.
  • R updates all packages with new updates if no packages are specified.

23.2 Arguments

The update.packages() function takes the following as arguments:

Argument Parameter Details
oldPkgs packages this updates all packages if no packages are specified*

*If you want to specify a certain set of packages, pass a vector c("package1", "package2", "package3") to let the function know that these are the packages you’d like to update.

You can read more about update.packages() in the function documentation here.

23.3 Overview

It is important to update packages for the following reasons:

  • Stay up-to-date with the most recent version of the package.
  • Meet requirements of other packages we are installing.
  • Avoid running into bugs or missing out on new features.

You can check if any packages need to be updated in two ways:

  1. Go to Tools -> Check for Package Updates
  2. Run update.packages() to get a list of all the packages that have new versions available.

When you run update.packages(), R will ask you if you want to update each of the packages currently installed one-by-one. Once it’s done going through all of your packages, it will start updating the ones you asked to update.

23.4 Exercises

23.4.1 Exercise 1

Run this code in your own RStudio.

23.4.2 Exercise 2

23.5 Common mistakes and errors

Below are some common mistakes and errors that you may come across while updating packages:

  • You try to update a list of packages without properly specifying that list of packages.
    • Specifically, you try to pass c("dplyr", "ggplot2") to update.packages() without specifying that c("dplyr", "ggplot2") belongs to the argument oldPkgs explicitly. This needs to be done in order for R to know that this is a list of old packages that you want to update.
  • You receive a pop-up from R asking you Update? and you forget to respond with Yes, No, or Cancel.
  • You try to use a function that has been recently changed in a package update and your currently installed package is out-of-date.

23.6 Next steps

If you would like to learn more about updating packages in R, here are some additional functions you may find helpful:

  • You can run old.packages() to see which of the packages you have are currently out of date.

23.7 Exercises

23.7.1 Question 1

23.7.2 Question 2

23.7.3 Question 3

23.7.4 Question 4

23.7.5 Question 5

23.7.6 Question 6

23.7.7 Question 7

23.7.8 Question 8

23.7.9 Question 9

23.7.10 Question 10