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! ❌
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.
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:
- For major releases (R 3.x -> R 4.x), reinstall all the packages;
- 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
; - For patch releases (R 4.0.1 -> R 4.0.2), no actions will be taken.
Usage:
Find the current location of R by running
Install R from https://cran.r-project.org/.
Install packages.
3.1 Open your new version of R and install the
updater
package withinstall.packages("updater")
.3.2 Install the previous libraries with
updater::install_pkgs
.
Refs:
- Tutorial: https://cran.r-project.org/web/packages/updater/refman/updater.html
- GitHub, @Daniel D. Sjoberg : https://github.com/ddsjoberg/updater
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()