How to Update R from R using the “installr” Package

How to Update R from R using the “installr” Package

Before we start

R is a powerful statistical/data science programming language. It is also an open-source program that requires regular updates to stay functionally up-to-date. There are different ways of upgrading R as specified in the R Official guidelines. Most users might go to the R Archive Network to download the up-to-date R version and install it. After installing the new version, you also need to install all required packages again with the new version R and choose to delete the old library if you no longer need it. This blog post introduces the installr package to automate the above mentioned process of updating R on Windows with a simple ‘updateR()’ command, which also takes care of the old version R packages without extra effort. Currently, this package only supports Windows OS, and we expect with the next update it will support Mac OS too.

Package Introduction

The installr package provides R functions for installing and updating software, and mostly focuses on R itself. This package can

  1. Upgrade R (on Windows) by running a simple function.
  2. Install all relevant software for R development, including:
    1. Git: a version control system for source code management.
    2. RTools: programs for building R packages from source.
    3. MikTex: for writing LaTeX.
    4. Pandoc: convert between numerous markup and word processing formats (HTML, LaTeX, Word docx, and PDF).
    5. Python, Java, Anaconda, RStudio, etc. 

When using this package, the software installation is initiated through a GUI. For example, you can run ‘updateR()’ to fetch the newest R version.  You can also run install.Rtools() to install the newest compatible version of Rtools automatically.

Install Package and Update R

To install the newest stable version of the package:

#install the package

install.packages(‘installr’)

Next, let’s run the function and update R.

#load the package

library(installr)

#update R

updateR()

Update R All in One

In general, the ‘updateR’ function will perform the following steps:

  1. Check your latest R version. If the currently installed R version is up to date, this function will return FALSE and end.
  2. If a newer R version exists, you will be asked to review the NEWS of the latest R version – to decide if to install the newest R or not.
  3. Then, you will press the “next” button to proceed. The function will download and install the latest R version.
  4. After the installation is done, you should press “any-key”, and the function will proceed with copying all of your packages from your old R installation, into your newer R installation.
  5. You can choose to erase all of the packages in your old R installation.
  6. After the packages are moved (and the old ones possibly erased), you can choose to update all of the packages in the new version R.
  7. You can open the new Rgui and close the current session of the old R.

Update R Step by Step

You can also break the previous steps into individual functions and choose what to run using the corresponding function:

# run the functions step by step 

check.for.updates.R() # if newer version R available or not

install.R() # download and run the latest version R installer

# copy packages to the newest R installation from the one version before it

copy.packages.between.libraries(from, to)

Possible Errors and Troubleshooting

If you get the following errors shown below:

Error in download.file(URL, destfile = …) :

Unsupported URL scheme

Or:

Install.RStudio()

Error in file(con, “r”): cannot open the connection

updateR()

Error in file(con, “r”): cannot open the connection

Based on the comments on Stack Overflow. Try running:

setInternet2(TRUE)

Other Features in installr

The package also offers functions for installing other software on Windows. You can find more details in the package manual.

RUG (R User Group)

If you have any question regarding R or just want to simply get started with it, do not hesitate to join us at the RUG (R User Group) meetings or to schedule a consultation with the GC Digital Fellows. Please also check the GCDI calendar for more events and get updated with the workshops and group meetings.

Reference

The content of this blog post is inspired and adapted from the following public materials, many thanks to these authors.

Updating R from R (on Windows) by Tal Galili

Skip to toolbar