Preparing for the course

Installing Git and setting up a GitHub account

Set up two-factor authentication. This is highly recommended!

Installing R packages

Install the tidyverse and sf packages:

We will use these packages more than anything else.

Now, install pak to get a better than basic installing packages:

Here are some of the other packages we are using in this class.

pak::pkg_install(
  c(
    "arcgis",
    "gt",
    "lwgeom",
    "mapview",
    "nycflights13",
    "osmdata",
    "quarto",
    "reprex",
    "rnaturalearth",
    "sf",
    "spData",
    "tidycensus",
    "tidyverse",
    "tigris",
    "tmap",
    "usethis"
  )
)

Always restart your session after installing new packages to make sure you are using the latest version and can access the package documentation.

Configuring RStudio

Configuring RStudio is something we do together as a class during our first session.

If you missed the first session, please review the instructions below to make sure your setup is the same as other members of the class.

Required changes

Select Tools \> Global Options from the menu then:

  • Under the “Workspace heading”, uncheck the “Restore .RData” box.
  • Under the same heading, “Save workspace to .RData on exit.” select “Never” from the drop-down.
  • Select the Code panel, then check the box “Use native pipe operator, |> (requires R 4.1+)”

Optional changes

Select Tools \> Global Options from the menu then:

  • Select the “Pane Layout” options. I recommend placing the console in the top-right pane and the help and plot viewer in the bottom left. This is a personal preference and you can try a few options to see what works best for you.
  • Select the “Appearance” options. This is the place you can customize the theme, code editor font, and code editor color scheme. Many programmers find a dark color scheme more readable. You may also want to try installing a “nerd font” or “programming” font. I use a font called FiraCode but you can find a wide variety of free fonts for download on this website.

Alternate IDEs

There are several alternate IDEs you could try:

  • Positron is an IDE created by Posit (the company that also developed RStudio) to support data science work in both Python and R. The application is based on VS Code and many VS Code extensions have been adapted to work with Positron. If you want to give it a try, you may find this Getting Started with Positron: A Quick Tour video helpful.

  • VS Code is a popular IDE with a wide variety of extensions. It does not have the built-in support for Quarto and RMarkdown out of the box so it may take some configuration to get it working. Check out the R in Visual Studio Code guide or the guide to using Quarto in VS Code for more information.

For this class, I recommend sticking with RStudio to ensure you are completing the exercises and project in the same environment that we are using during in-class sessions.

Set up GitHub credentials in RStudio

If you are using RStudio instead of GitHub Desktop to update your repository, you also need to set up some local credentials so GitHub knows that RStudio is allowed to make changes to your personal or course repositories.

The usethis documentation includes detailed article on connecting GitHub and R but it is more detail than you may need. These instructions are a brief summary of that article.

First, install the usethis package (if you don’t have it installed already):

install.packages("usethis")

There are three steps to connect GitHub and RStudio:

  1. Run usethis::create_github_token() to get a personal access token and copy the token to your clipboard. Make sure you are signed in to GitHub in your browser first! I also suggest setting the expiration to 90 days so you won’t need to refresh the token until after the end of this course.

  2. Run gitcreds::gitcreds_set() to put your PAT in your Git credential store.

  3. Restart your session and run usethis::gh_token_help() to double-check that the token is saved in the right place.

If you run into any trouble, you can run usethis::git_sitrep() for more feedback on what is set up correctly and what (if anything) might need to be fixed.