Jonathan C. Johnson

E-mail: jonathan.johnson10@okstate.edu
Office: MSCS 524
Department of Mathematics
Oklahoma State University

Installing R and RStudio

We will be using a couple of applications to analyze data during this course. The first one is a programming language, R. This is an interpreter which executes R code. The second is an integrated development environment(IDE),RStudio. This program is an interface for to you write R code, view plots, and do many other useful things. This is a guide to installing R and RStudio onto your computer.

If you have previous versions of R and RStudio, remove these first from your computer, and download the current versions (4.3.1).

Getting R

R can be downloaded from one of the “CRAN” (Comprehensive R Archive Network) sites. In the US, the main site is at http://cran.r-project.org/. Look in the “Download and Install R” area. Click on the appropriate link based on your operating system.

Mac OS
  1. On the “R for macOS” page, there are multiple packages that could be downloaded. If you are running macOS 11 Big Slur or higher, click on R-4.3.1-arm64.pkg; if you are running an earlier version of macOS, download the appropriate version listed under “Binary for legacy macOS/OS X systems.”

  2. After the package finishes downloading, locate the installer on your hard drive, double-click on the installer package, and after a few screens, select a destination for the installation of the R framework (the program) and the R.app GUI. Note that you will have to supply the Administrator’s password. Close the window when the installation is done.

  3. An application will appear in the Applications folder: R.app.

  4. Browse to the XQuartz download page. Click on the most recent version of XQuartz to download the application.

  5. Run the XQuartz installer. XQuartz is needed to create windows to display many types of R graphics: this used to be included in MacOS until version 10.8 but now must be downloaded separately.

Windows
  1. On the “R for Windows” page, click on the “base” link, which should take you to the “R-4.3.1 for Windows (32/64 bit)” page.

  2. On this page, click “Download R 4.3.1 for Windows”, and save the exe file to your hard disk when prompted.

  3. To begin the installation, double-click on the downloaded file. Don’t be alarmed if you get unknown publisher type warnings. Window’s User Account Control will also worry about an unidentified program wanting access to your computer. Click on “Run”.

  4. Select the proposed options in each part of the install dialog. When the “Select Components” screen appears, just accept the standard choices.

Linux (Ubuntu)
  1. Update the packages list using to following command:

    $ sudo apt-get update

  2. Install the R-base package using the following command:

    $ sudo apt-get install r-base

  3. After running the command, a confirmation prompt will appear. Answer it with a ‘Y’ for yes.

Getting RStudio

To download and install RStudio, follow the directions below

  1. Navigate to RStudio’s download site.

  2. Click on the appropriate link based on your OS (Windows, Mac, Linux and many others). Do not download anything from the “Zip/Tarballs” section.

  3. Run the installer.

    • For Windows or macOS

      1. Click on the installer that you downloaded. Follow the installation wizard’s directions, making sure to keep all defaults intact. After installation, RStudio should pop up in your Applications or Programs folder/menu.

    • For Linux(Ubuntu)

      1. Download and install the gdebi package using the following commands:

        $ sudo apt install gdebi
        $ install gdebi-linux

      2. Answer with a ‘Y’ for yes to confirm when prompted.

      3. Use the following commands to install the .deb package:

        $ sudo gdebi /path/to/the/file/.deb

Note that the most recent version of RStudio works only for certain operating systems (OS). If you have an older OS, you will need to download an older version RStudio, which you can find here.

The RStudio Interface

Open up RStudio. You should see the interface shown in the figure below which has three windows.

The RStudio Interface.

Let's take a closer look at the different parts of the interface.

  • Console, Terminal, and Background Jobs tabs (left)
    • Console - The console is used to run R code interactively. If you write a line of code after the screen prompt > and press enter, to code is immediately executed, and the results are displayed below.
    • Terminal - The terminal is a place for you to enter system commands directly in RStudio.
    • Background Jobs - This tab allows you to run scripts in the background.
  • Environment, History, Connections, and Tutorial tabs (upper-right)
    • Environment - This tab shows all the R objects that are currently open in your workspace including any variables you'ce defined and any data you’ve loaded into R. When you start a new session, R will clear all objects in this window. You can click on the bloom icon to clear out all the objects loaded and created in your current session.
    • History - This tabs shows a list of executed commands in the current session.
    • Connections - You can use this tab to connect to a variety of data sources, and explore the objects and data inside the connection. You can learn more about connections here.
    • Tutorial - This tab used to run tutorials that will help you learn and master the R programming language. These tutorials are provided by the learnr package.
  • Files, Plots, Packages, Help, Viewer, and Presentation tabs (lower-right)
    • Files - This tab shows all the files and folders in your current working directory.
    • Plots - This is where any charts, graphs, maps and plots you’ve successfully executed from the console are shown.
    • Packages - This tab tells you all the R packages that you have access to.
    • Help - This is where you can find documentation for R commands.
    • Viewer - This tab allows you to view local web content (won’t be using this much).
    • Presentation - This is tab allows to make HTML slideshows using R code and LaTex. You can learn more about R presentations here.