Peer Code Review

Week 9 · Tuesday, Nov 24 · Lecture

Dr. Marcela Alfaro Córdoba

Today’s plan

Time What
1:30 How to review code (and how to be reviewed)
1:45 Review, part 1: clone, restore, render
2:00 Review, part 2: read the runbook and the code
2:25 Review, part 3: write it, submit it
2:50 Read the review you got
3:00 Week 10

Learning goals: check that someone else’s project re-runs from a fresh clone; read code for correctness, readability and honesty, not just “does it run”; write feedback that is specific, kind and actionable.

Important

This is the peer review (5%). Written by you, no AI, submitted on Canvas before 3:00 pm today.

Who reviews whom

  • Assignments are on Ed (“Peer review assignments”). Each person reviews one repository, alone; in a pair, partners review different repos
  • Nobody reviews the repo of someone who reviews theirs
  • Your reviewer can’t clone your repo? Fix it now: make it public, or add them as a collaborator

Your own repo’s state at 1:30 pm is what gets reviewed. Don’t push during the session; you’ll fix things after reading your review.

How to review

The class code-review checklist

Ask How to check
Runs Does it render from a fresh clone, with no edits? git clone, renv::restore(), quarto render run-analysis.qmd
Reproducible Relative paths? Raw data untouched? No hidden state? Search for /Users/, C:\, setwd, rm(list
Readable Do names say what things are? Comments explain why? Repeated blocks? Read one script top to bottom; lintr::lint()
Correct Row counts at every join and filter? Missing values decided, and reported? Do the sentences match the tables and figures? Compare text with output; look for na.omit(), joins without checks
Honest Data sources and licenses? Limitations? “AI use” section? data/README.md, the end of the runbook
AI files Does AGENTS.md set real boundaries? Does the code follow STYLE.md? Read both, then spot-check one script

Good review comments

Not useful

Looks good! Maybe clean up the code a bit.

Useful: where, what, why, and a fix

R/03-join.R, line 14. na.omit(joined) drops every row with any missing value. In the render, the table goes from 812 to 640 rows, but the runbook doesn’t say so, and the text still says “all 812 respondents”. Suggestion: filter only on the columns the model uses, and report how many rows were dropped with inline code.

Review the code, not the person: “this line drops rows”, not “you forgot”. Kind, specific, actionable. Being reviewed: read it twice before you reply. A reviewer who found a problem saved you from finding it on Dec 3.

What to submit

On Canvas (graded), and also as one GitHub issue on their repository titled Peer review: <your name>, so the authors can act on it:

  1. Did it run? Yes / with changes (which?) / no (the first error, and the chunk label)
  2. Two strengths, specific (“the stopifnot() after the join caught…”)
  3. Two concrete suggestions: file, line, what, why, fix
  4. One question you’d want answered at their presentation
  5. One sentence: which checklist row is the project’s weakest, and why

Graded on how useful it is, not on how many flaws you found. “It ran and I found nothing wrong” is fine if you show how you checked.

Review

Part 1: does it run?

⏱ 15 min

  1. Clone the repo into a new folder (not inside your own project)
  2. Open it in Positron, renv::restore(), then quarto render run-analysis.qmd
  3. It fails? Write down the first error and the chunk label. Try one reasonable fix (a missing package?) and note it
  4. Still failing after 10 minutes? Stop. Review the code as written; “it didn’t run” is itself a finding

Don’t fix their code beyond that one step. Your job is to report, not repair.

Part 2: read it

⏱ 25 min

Go through the checklist, row by row. Take notes with file and line.

  • Read the runbook first, the way a newcomer would. Could you follow it?
  • Then read one script closely, top to bottom
  • Pick one number in the text and trace it: which code produced it? Is it inline code?
  • Pick one join or filter: is the row count checked?

Part 3: write it

⏱ 25 min

Write your review in the five parts (run, two strengths, two suggestions, one question, weakest row).

  1. Submit on Canvas
  2. Open the GitHub issue on their repo with the same text

No AI, including to “polish” the wording. Your own words, your own judgment.

Read the review you got

⏱ 10 min

  1. Read your review twice
  2. On the GitHub issue, reply with one sentence per suggestion: will fix, won’t fix (and why), or question
  3. Turn each “will fix” into a checkbox in the issue

These fixes go into your final report, which has to say how you used the feedback. The issue is your record.

Key points

  • A review starts with a fresh clone. “It runs on my laptop” is the author’s claim; a fresh render is the evidence
  • Read for correct and honest, not just tidy: row counts, missing values, sentences that match the output
  • Good comments: where, what, why, fix. About the code, not the person
  • Being reviewed is a gift that arrives before the grade

Week 10

  • Tue, Dec 1, 9:50-10:55: open time for independent project work (no check, no DS)
  • Tue, Dec 1, 1:30-3:05: project work + oral Q&A slots
  • Thu, Dec 3: presentations + oral Q&A
  • Finals week: final written report, with your runbook rendering from a fresh clone

Happy Thanksgiving. No class Thursday, Nov 26.