2.2 Update R

Q: How to tell which version of R you are running?
A: In the R terminal, type R.version.

The key thing to be aware of is that when you update R, if you just download the latest version from the website, you will lose all your packages!

On Windows use installr

The easiest way to update R and not cause yourself a huge headache is to use the installr package. When you use the updateR() function, a series of dialogue boxes will appear. These should be fairly self-explanatory but there is a full step-by-step guide available for how to use installr, simply select “Yes” when it asks if you would like to copy your packages from the older version of R.

# Install the installr package
install.packages("installr")

# Load installr
library(installr)

# Run the update function
updateR()

On Mac, can use updater

The package re-installs the packages and does not copy them from the previous R installation library. R packages for minor R releases (e.g. R 4.1 to R 4.2) may not be compatible, which is why its important to re-install the packages and not copy them.

Usage:

  1. Find the current location of R by running
> .libPaths()
[1] "/Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library"
  1. Install R from https://cran.r-project.org/.

  2. Install packages.

    3.1 Open your new version of R and install the updater package with install.packages("updater").

    3.2 Run

    updater::install_pkgs(lib.loc = c("<location(s) saved in Step 1>"))