Quality Matters Alignment: This assignment addresses QM Standards 2.1, 3.1, 4.1, and 5.2. Learning objectives are listed at the top of each Part. The rubric at the end provides grading criteria. Feedback will be returned within one week of the submission deadline.
Due: Before the start of next class
Submission: Rename this file
LastName_FirstName_NSCI253_HW_Wk11.Rmd and submit to Google
Classroom.
Total points: 50
This homework covers two foundational skills from Week 11: communicating results with R Markdown (Module 14) and Troubleshooting Strategies (Module 15).
Submission requirements:
.Rmd file that knits without
errors to HTML.challenge-a-fix).Academic integrity: You may use ?help,
r4wrds materials, and LLM tools as diagnostic aids. If you use an LLM,
briefly note what prompt you used and what you verified independently.
All explanations must be your own.
By the end of this assignment, you will be able to:
.Rmd file to HTML and interpret the relationship
between source and output.class(),
and ?function.Learning objectives: LO 1, LO 2
Look at the YAML header at the top of this file (between the
--- lines). Just below this heading, add a Markdown comment
block (<!-- ... -->) that explains in your own words
what each of the following fields does:
title:output: html_document:toc: trueerror: TRUE > Tip: Try changing
theme: from cosmo to journal,
knit, and > see what changes. Other options: flatly,
readable, spacelab.Demonstrate each of the three R Markdown components directly below this heading:
```{r my-first-chunk}) that creates a numeric vector of at
least 5 environmental measurements (e.g., stream depths, temperatures),
calculates its mean(), and uses at least one chunk option
(echo, eval, or include). Write
one sentence above the chunk explaining the option you chose.measurements <- c(12.3, 14.1, 13.8, 15.0, 12.9) mean(measurements)
Knit your document, then answer these questions in complete sentences in the space below:
.Rmd source?
Name one similarity and one difference.toc: false? Predict first,
then test it.HTML will hide the raw markdown syntax and show the formatted headings, bold text, and code output in a clear layout echo = TRUE was used. This caused the code to appear in the knitted document with the output changing toc: false, the table of contents would fail to appear in the HTML output. I tested it, I seen the sidebar disappeared with the document no longer showed section links. —
Learning objectives: LO 3, LO 5
For each challenge below:
error=TRUE chunk
as-is.challenge-X-fix with your
corrected code.# Challenge A: what is wrong here?
scores <- c(85, 92, 78, 90, 88)
sum(Scores)
## Error:
## ! object 'Scores' not found
Scores was capitalized is why the error happened. We all know R is case-sensitive. I carefully but noticed right away that the Scores was out of place, this is called READ by using lower case object name sum()
# STUDENT: paste your corrected code here
scores <- c(85, 92, 78, 90, 88)
sum(scores)
## [1] 433
mean() (5 points)# Challenge B: why does this return NA?
temps <- c(72, 75, NA, 68, 71)
mean(temps)
## [1] NA
# Hint: check ?mean -- look at the Arguments section carefully
The error was mean(temps) returning NA due to the reason the vector containing an NA and mean() propagates missing values Using CHECK, looking at mean and reading Arguments section adding na.rm = tells R to get rid of missing values before calculating the mean
# STUDENT: paste your corrected code here
```temps <- c(72, 75, NA, 68, 71)
mean(temps, na.rm = TRUE)
## Error in parse(text = input): attempt to use zero-length variable name
max() (5 points)# Challenge C: does this give the right answer?
dates_chr <- c("2023-01-15", "2023-06-30", "2023-12-01")
max(dates_chr) # seems to work... is it correct?
## [1] "2023-12-01"
max(as.Date(dates_chr)) # what changed and why does it matter?
## [1] "2023-12-01"
look at max(dates_chr) this will compare dates as character strings but not the actual dates. Just like before, READ was used as the debugging step You convert to Date class making R compare the underlying date values making sure the result is the most recent date.
# STUDENT: paste your corrected / clarified code here
dates_chr <- c("2023-01-15", "2023-06-30", "2023-12-01")
dates_date <- as.Date(dates_chr)
max(dates_date)
## [1] "2023-12-01"
# Challenge D: diagnose this join error
df1 <- tibble(id = 1:3, value = c("a", "b", "c"))
df2 <- tibble(ID = 1:3, score = c(10, 20, 30)) # note: "ID" not "id"
left_join(df1, df2)
## Error in `left_join()`:
## ! `by` must be supplied when `x` and `y` have no common variables.
## ℹ Use `cross_join()` to perform a cross-join.
# Check ?dplyr::left_join -- how do you specify the key column?
The is left_join() that fails due to df1 using id and df2 using ID. this causes R to struggle to find a shared column name. CHECK was used. The fix works by specifying by = c(“id”= “ID”) this will let R know which columns match
# STUDENT: paste your corrected code here
df1 <- tibble(id = 1:3, value = c("a", "b", "c"))
df2 <- tibble(ID = 1:3, score = c(10, 20, 30))
left_join(df1, df2, by = c("id" = "ID"))
## # A tibble: 3 × 3
## id value score
## <int> <chr> <dbl>
## 1 1 a 10
## 2 2 b 20
## 3 3 c 30
Learning objective: LO 4
Choose one scenario. In the space below, describe what you expect the
code to do and what actually happens. Run class() on the
problematic object, include the output, and explain why that class
causes an error.
mean().max().For this task, Scenario A was chosen, using the code to calculate the mean of readings, but it instead gave me a warning returning NA. I ran class() showing the values stored as “character” that stops numeric operations.
# STUDENT: use class() to inspect the problematic object here
readings <- c("5.2", "4.8", "6.1", "5.9", "5.0")
class(readings)
[1] "character"
## Error in parse(text = input): <text>:4:1: unexpected '['
## 3: class(readings)
## 4: [
## ^
Write a complete, self-contained reprex in the chunk below using Hadley Wickham’s four-component structure:
library() calls at the
top.tibble() or c(). Do not reference any external
file.# Expected: numeric mean; Got: warning + NA).Then add a Markdown paragraph explaining the fix, followed by a second chunk showing the corrected code.
# STUDENT: four-component reprex here
# 1. Packages: library(...)
# 2. Data: my_data <- ...
# 3. Code: ...
# 4. Comment: # Expected: ___; Got: ___
This error will happen when the readings are stored as character strings. R will not like mean on a text as it cannot compute it which results in the function returning NA.
# STUDENT: corrected code here
# 1. Packages
library(tibble)
# 2. Data
readings <- c("5.2", "4.8", "6.1", "5.9", "5.0")
# 3. Code
mean(readings)
## [1] NA
# 4. Comment
# Expected: numeric mean of the five readings
# Got: warning + NA because readings are character strings
Learning objectives: LO 1, LO 2
Create a separate .Rmd file for your
semester project following the project management format at https://r4wrds.netlify.app/intro/m_project_management.
Your project .Rmd must include at minimum:
title, author,
date, and output: html_document.Paste your project file’s YAML header and first section below. The full project file stays in your project folder.
title: “Pactola Watershed Water Budget” author: “Mike Yellow Boy” date: “2026-04-15” output: html_document: toc: true toc_float: true theme: cosmo —
# STUDENT: paste your project's first code chunk here
library(tidyverse)
QM Standards: 2.1, 3.1, 4.1, 5.2 · Total: 50 points
| Task | Criterion | Exemplary (Full Credit) | Proficient (Partial Credit) | Developing (Minimal Credit) | Points |
|---|---|---|---|---|---|
| Part 1 — R Markdown Structure (15 pts) | |||||
| 1.1 | YAML Annotations | All four fields annotated in the student’s own words with clear, accurate explanations; document knits to floating-TOC HTML. | 3–4 fields annotated, or explanations partially accurate or close to course materials. | Fewer than 3 fields annotated, or explanations missing or inaccurate. | 5 / 3 / 1 |
| 1.2 | Three Components | YAML annotated; body text uses heading + bold + hyperlink; labeled chunk has environmental vector, correct mean(), and explained chunk option. | Two of three components complete; minor errors in formatting, chunk option, or explanation. | One component complete, or chunk label, option, or explanation missing. | 5 / 3 / 1 |
| 1.3 | Knit & Reflect | Document knits; all three questions answered in complete sentences with specific observations, including testing toc: false. | Document knits; two questions answered, or answers vague but show understanding. | Document knits; one question answered or answers show minimal engagement. | 5 / 3 / 1 |
| Part 2 — Debugging Exercises (20 pts) | |||||
| A | Case-Sensitive Name | Original chunk preserved; fix runs correctly; explanation names the error (case sensitivity) and debugging step. | Code corrected; explanation partially accurate or wrong debugging step named. | Partial fix or explanation absent. | 5 / 3 / 1 |
| B | NA in mean() | Fix uses na.rm = TRUE; explanation describes NA propagation and references ?mean Arguments section. | Code corrected; explanation omits ?mean or misidentifies the mechanism. | na.rm not used correctly; explanation absent or inaccurate. | 5 / 3 / 1 |
| C | Date Class & max() | Both lines present; explanation distinguishes lexicographic (character) vs. chronological (Date) comparison with a concrete example. | Both lines run; explanation partially correct but does not distinguish the two comparison types. | Only one line addressed; explanation absent or incorrect. | 5 / 3 / 1 |
| D | Join Key Mismatch | Corrected join uses by = c(“id” = “ID”) or renames column; explanation cites ?dplyr::left_join and describes the by argument. | Join corrected; explanation omits ?dplyr::left_join or is incomplete. | Partial fix; explanation absent. | 5 / 3 / 1 |
| Part 3 — Write a Reprex (10 pts) | |||||
| 3.1 | Problem Identification | Describes expected vs. actual behavior; class() output included; explains why the class prevents the operation. | class() used; explanation of why the class is problematic incomplete. | class() not used or explanation missing. | 3 / 2 / 1 |
| 3.2 | Reprex Quality | All four components present; error reproduces; fix shown in second chunk with accurate explanation. | Three components present; error reproduces; fix shown but explanation brief. | Reprex incomplete (external data, missing packages); error may not reproduce; fix or explanation absent. | 7 / 4 / 1 |
| Part 4 — Semester Project Start (5 pts) | |||||
| 4 | Project Start | Complete YAML; Level 1 heading; labeled chunk with option loading a relevant package; 3+ sentence paragraph specific to the student’s project. | YAML and heading present; chunk missing options or generic; paragraph vague. | YAML incomplete; chunk unlabeled or absent; paragraph too short or off-topic. | 5 / 3 / 1 |
| A (45–50) | B (40–44) | C (35–39) | D (30–34) | F (< 30) |
|---|
Points earned: ________ / 50 Date returned: _______________
Comments: