Skip to main content

Assignment 2: R With AI

Purpose

This assignment turns the Week 3 R basics into a small auditable analysis note. You will load data with a relative path, inspect it before summarizing, use dplyr verbs, write one custom function, and document how any AI-generated code was checked.

Learning Objectives

  • Load R packages and import a CSV with a relative path.
  • Inspect rows, columns, variable types, and missingness before analysis.
  • Use filter(), mutate(), group_by(), and summarise() for a descriptive summary.
  • Write one small custom function and test it on the dataset.
  • Audit AI-generated code for wrong column names, missingness mistakes, and overclaiming.

Inputs

  • Week 3 page: weeks/week03-r-with-ai/index.qmd
  • Starter note: assignments/assignment02-r-with-ai/starter-analysis.qmd
  • Dataset: examples/nhanes-equity/data/nhanes_equity_v6.csv
  • Submission folder: assignments/assignment02-r-with-ai/submission/

Tasks

  1. Create the folder assignments/assignment02-r-with-ai/submission/.
  2. Copy the starter structure into analysis-note.qmd.
  3. Load readr, dplyr, and any other package used in the file.
  4. Import the NHANES CSV using a relative path from the repository root.
  5. Inspect the dataset with row count, column names, variable types, and missingness.
  6. Create one cleaned or analysis-ready table using at least three dplyr verbs.
  7. Write one custom function, such as a function that returns mean and SD for a numeric variable.
  8. Save a small output file named output/summary_table.csv — this is the required filename, and the starter note already writes it.
  9. Add AI audit comments near code that was drafted, debugged, or revised with AI assistance.
  10. Render the Quarto note to HTML.
  11. Commit and sync the source, rendered output, saved output file, and AI-use note.

AI-Use Expectations

AI may help draft code, explain an error, or suggest a function structure. You must verify that all column names exist, missing values are handled intentionally, outputs match the code, and interpretations remain descriptive. Include ai-use-note.md even if AI was not used.

Reproducibility Requirements

  • The analysis must render in GitHub Codespaces.
  • The data path must be relative.
  • Output files must be created by code, not manually edited.
  • Load every package used in the Quarto source and list it in dependency-note.md.
  • The course devcontainer is the dependency baseline. Do not initialize renv. If you think an additional package is necessary, ask before adding it and document the approved change so the work still runs in a fresh Codespace.

What To Submit

Place all submission files in:

assignments/assignment02-r-with-ai/submission/

Submit these files:

  • analysis-note.qmd [required]: Quarto source with data import, inspection, cleaning, function, and AI audit comments.
  • analysis-note.html [required]: rendered output.
  • output/summary_table.csv [required]: code-generated output. Use the required filename listed in this submission checklist — do not rename it to clean_data.csv.
  • ai-use-note.md [required]: what AI helped with and how you checked it, or a sentence saying AI was not used. Template and filled example: The Official AI Documentation Rule.
  • dependency-note.md [required]: packages used and whether any were added beyond the course environment.

Submission Route

Submit your GitHub repository link on Canvas after committing and syncing the required files.

Grading Checklist

Complete:

  • CSV is imported with a relative path.
  • Dataset inspection includes size, column names/types, and missingness.
  • dplyr workflow uses at least three verbs, as stated in the task list.
  • One custom function is defined and used.
  • Output CSV is generated by code.
  • AI-use note and dependency note are present.
  • Quarto file renders in Codespaces.

Incomplete:

  • Data path is absolute or machine-specific.
  • Code does not render.
  • Missingness is ignored or silently dropped.
  • Function is absent or unused.
  • Output file is missing or manually created.
  • AI-use or dependency note is missing.

Definition of Done

You are done when analysis-note.qmd renders, the output CSV is regenerated by code, and the Canvas submission links to the synced repository folder.