R and RStudio Setup

Before class on Monday, January 23, you should follow these instructions to set up the software that we’ll be using throughout the semester. Even if you’ve already downloaded both R and RStudio, you’ll want to re-download to make sure that you have the most current versions.

Highly recommended: Change the default file download location for your internet browser.

  • Generally by default, internet browsers automatically save all files to the Downloads folder on your computer. This does not encourage good file organization practices. It is highly recommended that you change this option so that your browser asks you where to save each file before downloading it.
  • This page has information on how to do this for the most common browsers.


Required: Download R and RStudio

  • FIRST: Download R here.
    • You will see three links “Download R for …”
    • Choose the link that corresponds to your computer.
    • As of January 17, 2023, the latest version of R is 4.2.2.
  • SECOND: Download RStudio here.
    • Click the button under step 2 to install the version of RStudio recommended for your computer.
    • As of January 17, 2023, the latest version of RStudio is 2022.12.0+353.


Suggested: Watch this video made by Professor Lisa Lendway that describes essential configuration options for RStudio.


Required: Install required packages.

  • An R package is an extra bit of functionality that will help us in our data analysis efforts in a variety of ways.

  • Open RStudio and click inside the Console pane (by default, the bottom left pane). Copy and paste the following command into the Console. You should see the text below appear to the right of the >, which is called the R prompt. After you paste, hit Enter.

    install.packages(c("ggplot2", "dplyr", "readr", "rmarkdown", "broom", "tidymodels"))
  • You will see a lot of text from status messages appearing in the Console as the packages are being installed. Wait until you see the > again.

  • Enter the command library(ggplot2) and hit enter.
    If you see the message Error in library(ggplot2) : there is no package called ggplot2, then there was a problem installing this package. Jump down to the Troubleshooting section below. (Any other messages that appear are fine, and a lack of any messages is also fine.)

  • Repeat the above step for the commands:

    • library(dplyr)
    • library(readr)
    • library(rmarkdown)
    • library(broom)
    • library(tidymodels)
  • Quit RStudio. You’re done setting up!

Optional: For a refresher on RStudio features, watch this video. It also shows you how to customize the layout and color scheme of RStudio.



Troubleshooting

  • Problem: You are on a Mac and getting the following error:
    Error: package or namespace load failed for ‘ggplot2’ in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]): there is no package called ‘rlang’
    Here’s how to fix it:
    • First install the suite of Command Line Tools for Mac using the instructions here.
    • Next enter install.packages("rlang") in the Console.
    • Finally check that entering library(ggplot2) gives no errors. You should be good now for dplyr, readr, and rmarkdown.