2  Download and Install R and RStudio

2.1 Questions

  • How does one install R and RStudio on their personal computer?

  • Can RStudio be used online via a cloud-based service?

  • Is it possible to work with alternative code editors when using R?

  • What steps are involved in installing RStudio?

2.2 Learning Objectives

  • Install the R programming language on your local machine.

  • Install RStudio as an integrated development environment (IDE) for R on your local machine.

  • Create an RStudio Cloud Account on the Posit Website.

  • Learn how to use alternative code editors.

2.3 Lesson Content

2.3.1 Introduction

Both the R and RStudio software are required to make full use of the R programming environment. R is the programming language, while RStudio is the integrated development environment (IDE) that has an easy-to-use interface. Here, we will focus on downloading R and RStudio for Windows from the respective websites. The instructions for downloading these two programs on Mac/Linux operating systems are available on the download websites.

2.3.2 Install R

To install R on your personal computer, visit the R Project for Statistical Computing’s Comprehensive R Archive Network CRAN. Follow the illustrated steps shown below:

2.3.2.1 Step 1

On the CRAN homepage, select the appropriate version of R for your operating system (Linux, macOS, or Windows; see Figure fig-cran-1).

Figure 2.1: The CRAN Homepage (Part 1)

2.3.2.2 Step 2

If installing R for the 1st time, click on “base” (Figure fig-cran-2).

Figure 2.2: The CRAN Homepage (Part 2)

2.3.2.3 Step 3

Click on the “Download” link for the latest version of R that is currently available (at the time of this writing, it was R-4.3.2). Once downloaded, run the executable file and wait for the software to be installed (Figure fig-cran-3).

Figure 2.3: The CRAN Homepage (Part 3)

2.3.2.4 Step 4

Once R is installed, open up the R software. The R graphical user interface should be similar to what is depicted below (Figure fig-r-console-1).

Figure 2.4: The R Console

2.3.3 Install RStudio

The RStudio IDE can be obtained from the “Download” section of the Posit website. Install the software by clicking on the “Download RStudio Desktop for Windows” button and running the downloaded program (Figure fig-rstudio-1).

Figure 2.5: The Posit/RStudio Download Page

Once installed, verify that the RStudio software has a similar graphical user interface to the one depicted in the image below (Figure fig-rstudio-console-1).

Figure 2.6: The RStudio Console

2.3.4 Create an RStudio Cloud Account on the Posit website

Posit (formerly RStudio) Cloud lets the user access the RStudio interface from their internet browsers (Figure fig-r-cloud-1). Using this option does not require any installation or specific software configuration to be implemented. Posit Cloud offers a free plan for casual users (without the need for a paid plan) and there is no need for dedicated hardware. Additionally, Posit provides a comprehensive guide for first-time users.

2.3.4.1 Step 1

Access the Posit Cloud Website (Figure fig-r-cloud-1).

Figure 2.7: The Posit/RStudio Cloud Homepage

2.3.4.2 Step 2

Sign up for a new user account (Figure fig-r-cloud-2).

Figure 2.8: The Posit/RStudio Cloud Login Page

2.3.4.3 Step 3

Log in to the new account, and you should see the page shown below (Figure fig-r-cloud-3). It includes the workspace where all projects will be hosted. On the top right-hand side of the website is a button that allows one to create a “New Project.” Additionally, the “Learn” and “Help” sections on the left panel can assist with troubleshooting.

Figure 2.9: The Posit/RStudio Cloud Workspace

2.3.4.4 Step 4

Create an R script to allow for code editing (Figure fig-r-cloud-console-1).

Figure 2.10: The Posit/RStudio Cloud Console

2.3.5 Using alternative code editors to work with R (Advanced Users)

Visual Studio (VS) Code is a code editor that can be used with various programming languages. For users that have previous experience with this code editor and would like to use it when reading this book, it is possible to use VS Code as an alternative to RStudio. After installing R, the “R Extension for Visual Studio Code” can be installed in the “Extensions” menu (Figure fig-r-vscode).

Figure 2.11: The R interface on Visual Studio Code

2.4 Exercises

  1. Download and install R and RStudio (If you have not already done so).
  2. Describe the steps involved in installing R on a Windows operating system.
  3. Are there any specific considerations when installing R on a macOS or Linux system?
  4. Set up a free RStudio Cloud Account on the Posit Website.
  5. Compare the local RStudio with the cloud-based RStudio and list the potential benefits/disadvantages of both.
  6. Verify your R installation by running a simple R script that prints “Hello, R! My name is (fill in the blank)” to the console.
  7. Can you customize the appearance or behavior of RStudio according to your preferences?

2.5 Summary

In this chapter, we have provided a step-by-step guide for downloading R and RStudio on the learner’s personal computer. Additionally, the learner has been shown how to set up an RStudio Cloud account on the Posit website, which allows for the use of R/RStudio using a web-based browser. Lastly, the learner has been shown how to access R/RStudio using alternative code editors such as Visual Studio Code. Overall, having a functional R and RStudio environment is key to gaining the most out of your learning journey. In the next chapter, we will navigate the R/RStudio interfaces and explain the various panes and menu options.