Skip to course content
Free R data course

R Foundations for Data Analysis

Module 02 Activity

Scenario

Read a colleague's script and find the assumptions it makes silently.

What you build

An annotated review of a short script, plus a corrected version.

Steps

  1. Rename every vague object so the name says what a row or a value is. Flag anything named after a base R function.
  2. Find each place two vectors are combined and confirm they are the same length or that one has length one.
  3. Find every comparison and decide what should happen when the value is NA. Replace any == NA with is.na().
  4. Find every comparison of computed decimals and replace == with all.equal().
  5. For each function the script calls, check the defaults that matter — especially na.rm — and state which the script is relying on.
  6. Turn the calculation that appears three times into one function with a guard on its inputs.

Evidence to hand in

Review checklist