Week 10
More
purrring
Topics
Part 10:
- Use
map()functions from thepurrrpackage to iterate functions - Nest datasets into list-columns, and iterate statistical modeling and/or visualization functions over those elements
- Use
map2()from thepurrrpackage to iterate functions across two inputs - Learn how to iterate regression modeling across different model variables
Announcements
- Please fill out the course evaluations for the class.
- Course evaluations are very helpful for making improvements to our classes.
- If too few students fill out the evaluations, they are not released to me.
- Please complete the SPH’s Annual Student Survey
- Responses help us improve our SPH programs!
- Cascadia R Conf in June 26-27 this year. It will be held at OHSU in RLSB. This is a great conference to meet other R enthusiasts in the area and learn more about what they are working on.

Class materials
- Class materials in OneDrive folder BSTA_526_W26_class_materials_public.
- For today’s class, make sure to download to your computer the folder called
part10. - Open RStudio by double-clicking on the project file called
BSTA_526_W26_class_materials_public.Rprojin the main OneDrive folder.
Note: The link to the slides version of the class notes is not working. Please see the OneDrive folder for the html of the slides.
| Part | OneDrive folder | Slides | Webpage |
|---|---|---|---|
| 10 |
Readings
Required
purrrtutorial by Jenny Bryan- This was listed as optional last week. If you haven’t read it, I strongly recommend the Core
purrrlessons, and in particular Introduction tomap(): extract elements.- Note: it uses
map_dfr()which is the “newer” version ofmap_df(), but both are superseded as ofpurrr1.0.0 though. Instead usedmap()combined withlist_rbind()as mentioned in part 9.
- Note: it uses
- This was listed as optional last week. If you haven’t read it, I strongly recommend the Core
gtsummary:tbl_regression()tutorial- Merge tables with
tbl_merge()
Optional
- Great classic
purrrresources. The drawback is that some of the functions have newer versions in the mean time. I am still recommending them though since they are classics and give great overviews ofpurrrandmap().- Joy of Functional programming talk by Hadley Wickham - more on nesting/iteration
- More on using map and nested data with modeling: Many Models
- This is from the 1st edition in the R4DS book and was removed in the 2nd edition.
- It’s a great introduction to using
map()on nested data.
- Combining
bromm’stidy()withpurrr:::map(): broom and dplyr
Suggested additional R readings
- Useful vignettes on table output: gtsummary intro to tbl_summary
- tidy evaluation: Programming with dplyr - in case I can’t get to tidy evaluation use for functions with tidyverse
- ggplot2 in packages
- Examples how to use ggplot inside functions. It’s meant for people writing packages, but’s helpful in general.
- Ted Laderas’s interactive workbook on learning rowwise and nested data: learning rowwise
- [Dates and times in R for Data Science](https://r4ds.hadley.nz/datetimes.html
- Cross tables with
gtsummary::tbl_cross()
For learning more about statistics with R:
- Modern Dive / Statistical Inference via Data Science by Chester Ismay and Albert Y Kim is a nice place to start: https://moderndive.com/v2/
- Danielle Navarro’s Learning Statistics with R is excellent and talks much more about statistics: https://learningstatisticswithr.com/
- Model Basics from R for Data Science
- More on survival analysis in R
- Survival Analysis in R Tutorial by Dr. Emily C Zabor
- Survminer survival plot vignette
- UVA’s Survival Workshop materials
- Rview’s Survival Analysis
tidymodelspackage
Post-class survey
- Please fill out the post-class survey to provide feedback. Thank you!
- Previous muddiest points and clearest points with responses are collected here.
Homework
- See OneDrive folder for homework assignment.
- HW 10 due on 03/12.
Recording
- In-class recording links are on Sakai. Navigate to Course Materials -> Schedule with links to in-class recordings.