R Windows

Intalling R and RStudio - Windows 10

Intalling R and RStudio - Windows 10

This is the third and last post in the Installing R and RStudio series, where I will describe the installation of R and RStudio on Windows 10.

Same as before, I will be installing the latest version of R (currently 4.0) and RStudio (1.2.5042) on a virtual machine with a clean and up-to-date version of Windows 10 (10.0.18363).

For a short introduction to R and also RStudio, please check the first post in this series.

Installing R

The Windows installation process is the simplest. You can go directly to the CRAN website that contains the R Windows base installer https://cran.r-project.org/bin/windows/base/ and download the installation file.

Note: You might have noticed that my Windows Taskbar is on the left side and not on the bottom. Today, the screens of most monitors is wide and I prefer to have the extra height and decided to have my taskbar on the left.

Windows Base Website at CRAN R Project

Windows Base Website at CRAN R Project

Now you just run the installer. I suggest you just install using the default settings and you should be fine. Some options, such as selecting the GUI preferences (MDI or SDI), can be changed later via R Console.

R Installer on Windows

R Installer on Windows

GUI preference: MDI vs SDI

MDI stands for Multiple Document Interface. It is an interface design for handling documents within a single application. When application consists of an MDI parent form containing all other window consisted of the app, then MDI interface can be used. Switch focus to a specific document can be easily handled in MDI. For maximizing all documents, parent window is maximized by MDI

Source: Diffzi

SDI stands for Single Document Interface. It is an interface design for handling documents within a single application. SDI exists independently from others and thus is a stand-alone window. SDI supports one interface means you can handle only one application at a time. For grouping, SDI uses special window managers

Source: Diffzi

In the screenshot gallery below, you can see the difference between SDI and MDI. The last screenshot it the gallery shows how to switch between MDI and SDI. In my opinion, the way it is done is strange. The steps are:

  1. Change between MDI and SDI
  2. Click on “Save” to save the Rconsole configuration file with the adjusted setting
  3. Click on “Cancel” and restart R Console. If you click on “OK", the same thing happens, but you will see the information message as shown in the screenshot

For me, this is strange, as I assumed that by pressing just OK, the configuration would be saved.

As also mentioned in previous posts, you will probably install a few packages to use with R (e.g. dplyr, ggplot2, Shiny, etc.), and while attempting, you will see the question “Would you like to use a personal library instead?".

Personal Library?

Personal Library?

You can simply click on Yes to create a personal library or run R Console as Administrator. Installing as Administrator has the advantage that other users using the same computer can use the same packages already installed, instead of having to install them as well.

To run R Console as Administrator (as long as you have the rights), just right-click on the R Console icon (R i386 4.0.0 or R x64 4.0.0), click on More and click on Run as administrator.

Running R as Administrator

Running R as Administrator

Running R Console as administrator (elevated) allows you to install the packages and be stored in Program Files in the R library folder.

After Installing Package DPLYR as as Administrator

After Installing Package DPLYR as as Administrator

As mentioned in two previous posts, some packages may have other dependencies. For example, the package xlsx requires Java and you will encounter an error if you try to load this package without having Java installed.

> library('xlsx')
Error: package or namespace load failed for ‘xlsx’:
 .onLoad failed in loadNamespace() for 'rJava', details:
  call: fun(libname, pkgname)
  error: JAVA_HOME cannot be determined from the Registry

Java SE Development Kit 14 (current version at time of writting) can be downloaded from: https://www.oracle.com/java/technologies/javase-jdk14-downloads.html.

After installation, it will load without errors (the second attempt, which was successfull, was made after installing Java JDK).

Loading Package XLSX with Java Installed

Loading Package XLSX with Java Installed

One last suggestion is to setup the R path in the Windows 10 Environment Variables so you can use it via command prompt.

Unlike macOS and Linux, if you try to run R from the Windows Command Prompt, it will inform that R is not recognized.

Where is R?

Where is R?

Follow the steps below to add R to the Windows path in the System Properties Environment Variables.

  1. Open the Start menu
  2. Start typing “View advanced system settings” and open it
  3. Click on “Environment variables
  4. Select Path from system variables
  5. Click on “Edit
  6. With Windows Explorer, open the R bin directory and copy to the clipboard the entire path (e.g. “C:\Program Files\R\R-4.0.0\bin”). I suggest so, as you may have a different version of R installed, and this also prevents you from entering the path incorrectly
  7. Back to the “Edit environment variable” dialog, click on “New
  8. Paste the path, and finish by pressing the “OK” button and closing all open windows

You can now open a Command Prompt and use R. If you have an open Command Prompt, you must close it first.

Adding R Path to Environment Variables

Adding R Path to Environment Variables

RStudio

On Windows, RStudio is also the best choice for developing with R.

The installation of RStudio on Windows is also very simple. Visit the RStudio Desktop (Open Source License) download website at https://RStudio.com/products/RStudio/download/#download, download the installer and run it.

Just follow the instructions and the installation should be complete in less than a minute. There is no settings to be made during the installation.

R and RStudio installed

R and RStudio installed

Summary

Installing R and RStudio on Windows is also easy, but feel free to contact me if you have any problems and need help installing it.