Module 03: Importing Data

Paths and Portability

Chris Chizinski

Slide Accessibility Note

  • Title Background Image Alt-Text: A photograph of organized filing cabinets and stacks of papers, representing the transition from physical data storage to organized digital project folders.
  • Speaker Notes: These slides cover the critical concepts of project-relative paths and data import strategies.

Reproducible Path Map

Project folder
Relative path
Import data
Run and inspect
Share repository

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

Module 03: Importing Data

  • Finish uploading Assignment 02, then move to importing data.
  • Today: project folders, here(), read_csv(), and import checks.
  • Assignment 03: Import and Inspect. Module 04 comes afterward.

Download and Open the Practice Project

Download Module 03 practice project (.zip)

  1. Extract the ZIP before opening any files.
  2. In Positron, choose File > Open Folder and open module_03_practice.
  3. Open scripts/week_03_follow_along.R in that folder.
  4. Keep both CSV files in data/. Run here::here() to check the project root.

How To Use Today

  • Find the project root first.
  • Use here() before you type a path by hand.
  • Verify that the raw data is still unchanged after import.

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

The Path to Reproducibility

  • Avoid absolute paths like C:/Users/Chris/Downloads.
  • Use the here package to find files relative to your project.
  • Keep your raw data “read-only”.

Learning Objectives

  1. Explain the value of relative paths.
  2. Use here::here() to find files.
  3. Import CSVs with read_csv().
  4. Skip metadata rows during import.

Live Coding: Section 1

  • Setting up the data/ folder.
  • Importing weather data.
  • Handling messy headers.
  • Checking the imported types and row count.

The Challenge [45 mins]

Problem: The Import Audit

  • Import stream_gauge_messy.csv with 5 rows of metadata.
  • Rename the discharge column so it is easier to read.
  • Identify missing values or suspicious values in the imported data.
  • Confirm that the row count changes the way you expect after skipping metadata.

Assignment 03 - Import and Inspect uses the same skill on stream_gauge_data.csv. Accept it in Classroom 50 (select NRES800), complete assignment.R at home, write your answers as # comments in the script, edit the README, and push from home. Due Sunday, Sep 27, 11:59 PM.

Verification

  • Does the script run on your neighbor’s machine?
  • Are you using here() and not setwd()?
  • Is your raw data still in the right folder and unchanged?
  • Can you explain why skipping the correct number of rows matters?
  • Assignment 03 is pushed from home; no in-class upload this time. Feedback arrives as an Issue in your repository.