Skip to main content

Before the First Class

This page gets your computer ready for the course. Plan on 30 to 45 minutes, most of which is waiting for things to download, and please do it before our first meeting, so we can spend class time on statistics and not on installation troubleshooting. Week 1 explains why the workflow looks the way it does; this page is just the steps.

Step 1: Install R

R does the computing. Download it from CRAN:

  • Windows: click “Download R for Windows,” then “base,” then the download link at the top of the page. Run the installer and accept the defaults.
  • macOS: click “Download R for macOS” and choose the installer that matches your Mac. Macs with Apple silicon (M1 and later) use the arm64 version, and older Intel Macs use the x86_64 version. If you aren’t sure, click the Apple menu and choose “About This Mac.”
  • Linux: follow the instructions for your distribution on the CRAN page.

The course uses R 4.6. If you already have an older version, install the new one.

Step 2: Install Positron

You won’t type code into R itself. You’ll work in Positron, an editor made by Posit, and that’s what we use in class. It includes Quarto, so you can open and render the .qmd files for the course, and it includes the Posit Publisher extension we’ll use to share homework. Install R first (step 1), then Positron:

  1. Go to https://positron.posit.co/download, accept the license, and download the installer for your computer.
    • Windows: if you’re offered a user installer and a system installer, choose the user installer. It doesn’t need administrator rights, which matters on a UTSA-managed laptop.
    • macOS: open the downloaded .dmg file and drag Positron into your Applications folder.
  2. Run the installer and accept the defaults.
  3. Open Positron. The first time, it finds your R installation and starts an R session in the Console, the pane at the bottom of the window. If you see R 4.6 (or similar) near the top right of the window and a > prompt in the Console, it’s working. If it can’t find R, click the interpreter button at the top right and choose your R installation, or restart Positron after checking that R installed correctly.

If you’ve used RStudio before, most of Positron will feel familiar: the editor, the Console, plots and help are all there, laid out a little differently.

Step 3: Windows only, install Rtools

A few packages (brms in week 12, mainly) compile code in C++, and on Windows that needs Rtools. Choose the version that matches your version of R and accept the defaults. On a Mac, the equivalent is the Xcode command line tools: run xcode-select --install in the Terminal.

Step 4: Install the course packages

Open Positron, then copy this line into the R Console and press Enter:

source("https://raw.githubusercontent.com/coreysparks/DEM7283/master/install_first_7283.R")

The script installs pak, a faster installer that uses prebuilt packages, and then hands it the list of packages for the semester, plus my sparkscolors package from GitHub. It skips anything you already have, so if it stops partway through (a dropped connection, a laptop going to sleep), run it again and it picks up where it left off. When it finishes, it prints Done. Restart R before you start working.

You should never run code from the internet that you haven’t looked at, mine included. The script is short.

Step 5: Install Git and create a GitHub account

You’ll keep your homework in Git and share it on GitHub, starting in week 1. If you’ve never used either, don’t worry; Week 1 explains what they are and walks through the whole setup. Before the first class, please do the first two steps from that section:

  1. Create a free GitHub account at https://github.com. Use an email address you’ll keep after you graduate, and pick a username you’d be happy for a future employer to see.
  2. Install Git. On Windows, download Git for Windows from https://git-scm.com/downloads/win and run the installer. The defaults are fine except for two questions: for the default editor, choose Notepad instead of Vim, and for the name of the initial branch, choose to override it and type main. On a Mac, open the Terminal app and type git --version; if Git isn’t there, macOS offers to install it.

We’ll do the rest of the setup (connecting R to your GitHub account) together in class.

Step 6: Get the course repository

The data and the helper functions the chapters use live in the course repository. Week 1 shows you how to clone it with Git. If you want to look around before then, the green Code button on the repository page has a Download ZIP option.

Step 7: Get a Census API key

A few of the chapters download data from the Census Bureau with tidycensus, which needs a free key. Request one at https://api.census.gov/data/key_signup.html; it arrives by email in a few minutes. Weeks 2 and 6 show you where to put it.

Troubleshooting

A package fails to install. Read the message, then try installing that package by itself, for example pak::pak("survey"). On Windows, if the error mentions make or a compiler, check that Rtools is installed (step 3). On a Mac, if it mentions clang or gfortran, install the Xcode command line tools.

The script can’t reach GitHub. Campus and corporate networks sometimes block it. Try again from a different network.

Something else. Copy the full error message and bring it to class or office hours, or email it to me. Error messages look scary, but they usually tell you exactly what went wrong.

What gets installed

Packages What we use them for
knitr, rmarkdown, quarto, here, renv, usethis, gitcreds, rsconnect Rendering documents, project paths, package versions, Git, and publishing (week 1)
tidyverse, haven, ipumsr, tidycensus, tigris, skimr, scales Reading and managing data, Census downloads, and graphics
survey, srvyr, svyVGAM Complex survey design (week 2 onward)
modelsummary, marginaleffects, gtsummary, broom, broom.helpers, car, Hmisc Model tables, predicted probabilities and marginal effects
VGAM, pscl, betareg Ordinal, multinomial, count and proportion models (weeks 3 to 6)
oaxaca Decomposition (week 7)
mice, mitools Multiple imputation (week 9)
geepack, fixest GEE and fixed effects models (week 10)
lme4, WeMix, brms Multilevel models (weeks 12 and 13)
dagitty, ggdag, MatchIt, WeightIt, cobalt, EValue Causal inference (week 14)
tidymodels, probably, ranger, xgboost, rpart.plot Machine learning (week 15)
sparkscolors UTSA colors for graphs (from GitHub)