Instructor notes: Session 1
R basics, importing, and inspecting data
Timing
| Part | Topic | Time (incl. TRY IT) |
|---|---|---|
| 1 | R basics | 12 min |
| 2 | Installing and loading packages | 8 min |
| 3 | Project folders and here() |
10 min |
| 4 | Importing data | 10 min |
| 5 | Inspecting data (4 TRY ITs) | 30 min |
| 6 | The problem list (class + TRY IT) | 15 min |
| Wrap-up and preview | 5 min | |
| Total | 90 min |
Short on time? Make TRY IT 8 (the measles problem list) homework — learners need it at the start of Session 2.
Why this order
The session starts with the basics of the language (objects, vectors, functions), then the tools learners will use every day: packages, the project folder, importing, and inspecting. The pipe %>% is taught at the start of Session 2, together with the tidyverse cleaning it is used for, so Session 1 calls one function at a time.
Before you start
- Check that everyone ran the Setup test. Anyone who didn’t should start
install.packages()at the very beginning of class — it can take several minutes, and Part 1 (R basics) needs no packages, so they can follow along while it installs. Windows users may need Rtools and Mac users may need the Xcode Command Line Tools (Troubleshooting). - Hand out the green and red sticky notes and explain them.
Teaching notes by part
Part 1 — R basics. Keep this brisk (about 10 minutes); learners will practice all of it in every later session. Have someone make a deliberate mistake (Mean(ages)) to show that R is case-sensitive. The data frame example uses base R’s data.frame(), because no packages are loaded yet; mention that the tidyverse version, the tibble, shows up later.
Part 2 — Packages. Learners who did the setup only need the library() lines.
Part 3 — Project folders and here(). Show that here::here() points at the workshop folder because it’s open in Positron (and has a .here file). The workshop uses Positron for everyone, so the setup and pane names are the same on every laptop.
Positron vs RStudio names: if learners follow older tutorials, Positron’s Variables pane is RStudio’s Environment pane, and the Explorer is the Files pane.
Part 5 — Inspecting. This is the longest part. The “Think about it” questions on the lesson page are prompts to ask the class:
- What is wrong with these column names? — spaces, dots, capitals, mixed styles.
- Which column types look wrong? —
date.onsetis text,ageis text, andage_unithints that some ages aren’t in years.
After skim(), point at the n_missing column, the negative minimum of wt_kg, and the near-300 cm maximum of ht_cm.
The 🔁 base R table() box takes 2 minutes. The point is not to learn a second counting function but to recognize it in other people’s code, and to know its trap: it hides NA unless you add useNA = "ifany". TRY IT (b) lets learners find this themselves.
Zooming in uses one function inside another, such as head(arrange(linelist_raw, wt_kg), 10). Read it aloud from the inside out (“arrange the data, then take the head”). Let learners feel that the brackets get awkward: it sets up the pipe at the start of Session 2.
Part 6 — The problem list. Build the list with the class — ask learners to call out what they found before showing the table. Make sure they save their measles problem list: Session 2’s TRY ITs work through it.
TRY IT answers at a glance
The numbers match the TRY IT numbers in the lesson, the student script, and the solutions file. Follow-along prompts are numbered by part (Follow along 5.3 = Part 5, third prompt).
| TRY IT | Answer |
|---|---|
| 1. Objects and functions | mean(my_temps) is 38.5 |
| 2. Path to the practice data | here::here("raw_data", "measles_raw.csv") |
| 3. Import | 1215 rows, 11 columns |
| 4. Size and structure | Age (years) is text; six names need backticks |
| 5. Categories | a) District has 18 values; “North” and “No” are each written 4 ways b) table() drops the 34 NA districts |
| 6. Zooming in | head(arrange(measles_raw, desc(`Temp (C)`)), 10): highest temperature 104.7 — Fahrenheit (27 temperatures in °F) |
| 7. Missing values and duplicates | 37 missing IDs, 15 duplicates; Days in Hospital has 766 NAs (not hospitalized) |
| 8. Problem list | At least 8 problems — see the lesson’s solution |