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:
- Update a package using
update.packages()
. - Understand what R outputs when you run
update.packages()
.
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:
- Go to Tools -> Check for Package Updates
- 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.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")
toupdate.packages()
without specifying thatc("dplyr", "ggplot2")
belongs to the argumentoldPkgs
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.
- Specifically, you try to pass
- You receive a pop-up from R asking you
Update?
and you forget to respond withYes
,No
, orCancel
. - 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.