2.2 Update R

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

sessioninfo::session_info() print information about the current R session, including the R version, packages loaded, and where they were loaded from.

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!

Q: How to understand the version number?
A: The version number is in the format major.minor.patch, e.g. 4.3.1. The first number is the major version, the second is the minor version, and the third is the patch version. Major versions are released every 18 months, minor versions are released every 6 months, and patches are released as needed.

2.2.1 Update R on Mac

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 even 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.

Q: What updateR does?
A: {updateR} restores old libraries from previous version with the following actions, depending the type of releases:

  1. For major releases (R 3.x -> R 4.x), reinstall all the packages;
  2. For minor releases (R 3.5.x -> R 3.6.x), users may choose between reinstall or copy and pasteall the file folders under /Library/Frameworks/R.framework/Versions/[old\_version]/library to /Library/Frameworks/R.framework/Versions/[new\_version]/library;
  3. For patch releases (R 4.0.1 -> R 4.0.2), no actions will be taken.

Usage:

  1. Find the current location of R by running

    > .libPaths()
    [1] "/Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library"
  2. Install R from https://cran.r-project.org/.

  3. Install packages.

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

    3.2 Install the previous libraries with updater::install_pkgs.

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

Use example

> library(updater)
> install_pkgs(lib.loc = c("/Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library"))

── Importing Package Information ───────────────────────────────────────────────
ℹ Found 377 packages
→ CRAN: abind, AER, alphavantager, anytime, AsioHeaders, askpass, assertthat, backports, base64enc, bayestestR, bdsmatrix, BH, bigD, bit, bit64, bitops, blob, bookdown, …, zip, and zoo
→ GitHub: addinexamples, ggplot2, httpgd, rstudiothemes, xltabr, and xtsExtra
→ R-Forge: IntroCompFinR
→ Unknown: shoRtcut and shoRtcut2

── Installing Packages ─────────────────────────────────────────────────────────
ℹ Packages in repositories CRAN, R-Forge, and Unknown will be installed from CRAN (<https://cran.rstudio.com/>)

Do you want to proceed? [y/N]: 

Type y to proceed with the installation of packages.

A progress bar and ETA will show the Estimated Time Remaining until the installation is finished. It will take a while to install all the packages, depending on your internet speed and the number of packages you have installed.

For a moderate user, it may take about 10 minutes to install all the packages.

Refs:


2.2.2 Update R on Windows

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()

2.2.3 Caveats about updating R

Be aware that some package updates may cause your previous code to stop working.

  • For this reason, we recommend updating all your packages once at the beginning of each academic year (or semester) – don’t do it before an assessment or deadline just in case!

Q: When should I update R?
A: When I see many packages print a warning message that they are built under a newer version of R, I will update R. Every 6 months or so would be quite sufficient.