Skip to main content

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

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)