In this recipe, you will learn to install R in the Windows platform and we will address other necessary configuration issues that are related to the Windows operating system.
To start this recipe, you will need to know your version of the Windows operating system, for example, whether it is Windows 7, 8, or 10. Also, you need to know specific architecture, such as 32-bit or 64-bit. Once you know the particulars of the operating system, you are ready to install base R by following the steps in the next section. Another thing that you need to check is whether R is already installed on your computer or not. You can easily check by inspecting the Start menu or task bar or desktop icon. Now, let's assume that you did not install R previously in your computer and this is the first time you are going to do so.
Once you get detailed information about your operating system, you will need to download the executable file for the Windows operating system. To find the latest version of R, you can visit the Comprehensive R Archive Network (CRAN) at http://cran.r-project.org/. On this web page, you will get to know the latest release of R and other related information.
To download the latest release of R for Windows, perform the following steps:
- Visit https://cran.r-project.org/bin/windows/, which will show you the following screen:
- On this web page, you will see base under the Subdirectories category. As a first-time user of R, you need to download the executable file from this link.
- Once you click on base, you will end up on this page, https://cran.r-project.org/bin/windows/base/ as shown in the following screenshot:
- Now, click on Download R 3.x.x (This version number might differ because during preparation of this recipe, the version was 3.3.3) for Windows. The executable file will be downloaded into your local storage.
Once you have downloaded the executable file, you are ready to install it on your computer. Perform the following steps and choose the options accordingly. The screenshots are for your convenience only:
- Go to the folder where you have stored the executable file that you have downloaded, by following the instructions in the previous section.
- If you have administrator privileges, then just double-click on the executable file, or right-click on the mouse and select Run as administrator:
- In Windows 7, it will show a notification with the title User Access Control. In this case, you must choose Yes to proceed.
- The first thing it will ask you to do is choose a language, as shown in the following screenshot. Once you select your chosen language, click on the OK button. The R Setup Wizard will appear, and you will see various options to select in different pages:
- Click on Next > on this page to proceed with the installation:
- On this page, the GNU GENERAL PUBLIC LICENSE information will be displayed, and you will be asked to read and understand the licensing agreement and then click on the Next > button:
- Now, you will be asked to choose the destination folder where you want to store the installation files. Usually, by default, it shows C:/Program Files/, and sometimes, it also shows one more level C:/Program Files/R/R-x.x.x. You can keep the default location, or you can choose a separate destination based on your choice. Once you have selected the destination, click on the Next > button:
- At this stage, you will get the option to select the component that you want to install. You can choose either 32-bit Files only, 64-bit Files only, or both along with core files and message translation. After selecting the components, again click on the Next > button:
- Now, you will be asked whether you want to customize your startup or accept the defaults. The recommended option at this stage is to accept the defaults and click on the Next > button:
- You can decide whether you want to create the start menu folder or not and you can specify its name at this stage of installation:
- Finally, you will be given the option to choose whether you want to create a desktop icon and also create a quick launch icon. You can specify whether you want to save the version number into the computer's registry or not, and the last option is to associate file name extensions .R and .RData with the software. Once you are done with selecting the options, click on Next > and the installation will be started:
Once you follow the steps described in the How to do it… section, the R software will be installed, and it's ready to use. You can open R using either the desktop icon or quick launch icon, or from the Start menu.
However, to do some advanced-level work in R or if you want to open the R console from the Windows Command Prompt, you need to do some configuration that is specific to the operating system. In this subsection, you will see how the configuration works.
If you want to access the R terminal from the Windows Command Prompt, then you must open the Windows Command Prompt, and then type R and press Enter. However, without correctly configuring R, you won't be able to open the R terminal in this way. The following are the steps to configure R:
- Right-click on the Computer icon and select Properties from the following screen:
- Now, click on Advanced system settings. It will open up the System Properties window as shown in the following screenshot:
- At the bottom of the System Properties window, you will see Environment Variables…. Click on it and it will show the following screen:
- The Environment Variables window will pop up in which you will see two separate sections, one for User variables and another for System variables.
- In the System variables section, select the Path variable and then click on Edit…:
- Now, in this Path variable, add the location where you have installed R software. Choose the location where the R.exe and R.dll file belongs, for example, C:\Program Files\R\R-3.3.2\bin\x64.
- Put the location at the end of the Path variable after putting in a semicolon (;) and then click on OK on each of the window opened.
Once you have performed the preceding steps, it is the time to check whether you have correctly configured environment variables by performing the following steps:
- Go to the Start menu.
- Type cmd in the search box.
- Then, click on cmd.exe. It will open a black screen called Windows Command Prompt:
- Type R and hit Enter. If the R console opens, then everything is alright and you have correctly configured R in Windows:
If you want to customize the R console, its display font, font size, and others, you can edit the preferences from the menu. For example, navigate to Edit | GUI preference…. You will see the following screen. You are now able to change anything you want to customize your R console and other things:
In this recipe, you have gone through the steps based on the Windows operating system. If you want to install and configure R for Linux, see the next recipe Installing and configuring base R in Linux.