Module 02: Objects & Debugging

Everything is an Object

Chris Chizinski

Slide Accessibility Note

  • Title Background Image Alt-Text: A close-up image of a computer screen displaying multiple R error messages in red text, symbolizing the debugging process.
  • Speaker Notes: These slides explain the fundamental nature of R objects and how to diagnose errors.

Debugging Loop

Symptom
Inspect object
Read the error
Change one thing
Run again

Use this map to track where each live-coding step fits in the larger workflow.

How To Use Today

  • Read the error message before touching the code.
  • Use the Environment pane as a diagnostic tool.
  • Fix the cause, not just the symptom.

Download the Module 02 follow-along script (.R)

R is for Objects

  • Everything that exists in R is an object.
  • Everything that happens is a function.
  • Objects have types (numeric, character, logical).

Learning Objectives

  1. Create and name R objects.
  2. Identify common data types.
  3. Inspect data frames in the Environment.
  4. Interpret and fix common R errors.

Live Coding: Section 1

  • Creating vectors and data frames.
  • Breaking R on purpose.
  • Interpreting error messages.

The Challenge [45 mins]

Problem: The Debugging Clinic

  • Open debug_this.R in your Assignment 02 repository.
  • Fix 3 intentional errors and explain each cause in a code comment above the fix.
  • Inspect a small soil dataset before deciding what to fix.
  • Extension: Convert a column type and create a logical pH check.
  • Base goal: Get the script running from top to bottom.
  • Extension goal: Explain each fix in plain language.

To get the repository: sign in to Classroom 50 with your GitHub account, select NRES800, and create Assignment 02 - Debugging Clinic. Clone it in Positron the same way as Assignment 01.

Verification

  • Does the script run without errors from top to bottom?
  • Can you identify the object-name, data-type, and plotting errors?
  • Did you save debug_this.R and your explanation comments?
  • Did you replace the README paragraph with 2-3 sentences of your own?
  • We upload together at the start of class. This is the last supported upload; Assignment 03 is pushed from home.
  • Due Tuesday, Sep 22, 11:59 PM. Feedback arrives as an Issue in your repository.