Week 9: Writing Custom Functions & purrr
Nov 4, 2026 ยท 2:00โ4:40 PM ยท Bobst LL138
Before class
- Read: R02Pro Ch 13
- Review the newly released weekly exercise and prepare questions.
- Complete Weekly Exercise 8 (due tonight at 11:59 PM).
- ๐ Quiz 4 (20 min, covers Weeks 7โ8) will be held during the last 30 minutes of class.
- ๐ Proofreading corner: spot a typo or unclear passage in Ch 13? Submit a PR or issue for extra credit (see syllabus).
Topics
- Defining custom functions: function(args) { body }
- Argument defaults, return values, and lexical scoping rules
- Defensive programming: stopifnot() and custom error messages
- Functional iteration with purrr: map(), map_dbl(), and list_rbind() (formerly map_dfr())
- Comparing for loops vs purrr::map
Materials
- ๐ Lecture Slides: Interactive Presentation (HTML)
- ๐ In-Class Exercise: View Worksheet (HTML) ยท Download Starter Code (
.qmd) ยท or runget_worksheet(9)in your in-class repo - ๐ป Weekly Exercise 9: Accept Assignment on Classroom 50 ยท How to do it, start to finish
Due
- Weekly Exercise 8 (due tonight at 11:59 PM)
- In-class exercise 9 (pushed to GitHub by end of class)
- Quiz 4 (20 min, covers Weeks 7โ8)