Friday, May 29, 2026
dplyr pipes, ggplot2 basics, aesthetics, geoms, facets, stats, position adjustments.When you finish, turn in your quiz up front and we’ll get started with the rest of class.
The course AI policy is on the syllabus.
AI tools are allowed for this course, with disclosure. But “allowed” doesn’t mean “use uncritically.”
Tip
When you code with AI’s help, you are still the one responsible for the code and you must be able to explain/defend each line you (or AI) submits.
When I say “AI” today I mean things like:
The patterns we’ll discuss apply across all of them. How can we use these tools without making mistakes we can’t catch?
The output of a good AI model looks correct even when it’s wrong.
You can’t catch a confident-sounding wrong answer by reading it the way you’d skim a textbook. You have to actively verify.
Here’s why we are still teaching coding in a world with AI:
The skills you’re building this summer (knowing what group_by does, how aes() works, what mean(x, na.rm = TRUE) means) are exactly the skills that let you catch AI mistakes.
This isn’t an exhaustive list, but here’s four general categories:
You ask: “How do I make a violin plot in ggplot2 with the median marked?”
AI confidently produces:
stat_median_marker() is not a real ggplot function. It sounds like it could be. The AI generated something plausible.
Warning
The actual answer is stat_summary(fun = median, geom = "point", color = "red"). The fake function gives a clean error when you try to run it— but a busy student might paste it, see the error, and assume they did something wrong.
You ask: “What’s the average flipper length for each species, in mm?”
AI produces:
# A tibble: 3 × 2
species avg_flipper
<fct> <dbl>
1 Adelie NA
2 Chinstrap 196.
3 Gentoo NA
That runs fine and gives you some numbers. But two values are NA.
Why? flipper_length_mm has missing values, and mean() returns NA by default if any input is NA. The right answer needs na.rm = TRUE. Since you didn’t explicitly ask for this setting, AI made a choice itself and did not implement this step (even though it definitely knows about na.rm).
Warning
The potential issue here is that the output table looks like an answer. If you copy the numbers into a report without running the code yourself, you’ll write “the average flipper length for Adélies is NA” and not notice.
The tidyverse, the palmerpenguins`, and even R itself changes. However, AI training data has a knowledge cutoff.
If you ask: “How do I select multiple columns with a name pattern?”
A model might give you:
one_of() has been superseded by any_of() and all_of(). It still works (for now), but it’s not the modern recommended approach.
A worse situation is a model confidently using functions that were removed in a recent version. This will likely throw errors with no obvious cause.
You upload a CSV and ask: “Plot the relationship between price and size.”
AI produces:
The AI cannot see your data. It is guessing about:
data is even the right object name$price or Price_USD or cost_dollars?)size is a continuous variable or a category like S/M/LIt assumed all of these in a way that might match your data and might not.
Whenever you use AI-generated code, you should be able to:
?function_name), the original textbook, the actual data itself, etc.If the code has a function you’ve never seen, stop and look it up using a trustworthy resource.
?function_name in Rdplyr.tidyverse.org)If you can’t articulate what every line does to a classmate, you are not yet ready to submit it.
Tip
One thing you can try is taking a chunk of AI code, deleting all the comments, and writing your own comments above each line. If you get stuck on a line, that’s the line to investigate.
Before trusting summary numbers, sanity-check against what you already know.
The AI tells you the average penguin weighs 4200g.
nrow(penguins) vs the rows used in the calculation)NAs being silently dropped or silently propagated?If the AI gives you a plot with three lines and your data has four species, something is off.
Warning
One of the more common “AI gave me wrong numbers” failure modes is silent NA handling. Either na.rm = TRUE was used when it shouldn’t have been (treating missing data as if it didn’t exist) or it wasn’t used when it should have been (giving you NA when you wanted a number).
When the AI tells you something, ask: does another source agree?
?function)If you cannot verify a claim with some independent source, you don’t actually know if it’s true.
Note
This isn’t unique to AI. It’s just how you should treat any source you don’t fully trust.
Every homework template has an “AI Disclosure” section near the top:
- [ ] No AI used
- [ ] Syntax / Debugging (e.g., finding a missing comma, fixing an error)
- [ ] Conceptual explanation (e.g., asking how ggplot() layers work)
- [ ] Code Generation (e.g., asking AI to write a function from scratch)
You should:
Tip
A good disclosure: “Used Claude to debug a missing parenthesis in my mutate() call. Used Claude to explain what after_stat(prop) does.”
A bad disclosure: leaving the box unchecked when you did use AI.
?function): noRoughly 25 minutes
Format: I’ll give you a moderately complex analysis question on a dataset. You’ll:
You must disclose what AI you used and how. The assignment is graded on the quality of your verification, not on whether your first attempt was correct.
When you verify your own AI output, you’re looking for:
?function_name?Write down what you found, what you changed, and why.
Next Monday: Week 3 starts. We move from making plots to wrangling data (joins, pivots, the full dplyr verb set).
Tip
Take-home for the weekend: the next time you use AI for coding, try articulating to yourself what every line does before you run it. If you can’t, that’s the line to investigate further.
Upcoming Deadlines
Reach out
Stuck? Office hours, or email me (cgc5478@psu.edu) or Xinyue (xpw5228@psu.edu).
Reference
Syllabus · AI policy · Schedule · R4DS · DC · ggplot2 reference