GitHub
LinkedIn
Twitter
YouTube
RSS

Functional Programming with purrr

Functional Programming with purrr

Course Level: Foundation

This is a one-day course on the {tidyverse} package, {purrr}. {purrr} is a very powerful package that gives great flexibility to analysts, by enhancing R’s functional programming toolkit. We will demonstrate how to use functions such as map(), map2() and pmap(), to iteratively map functions over multi-element objects like vectors and lists. Emphasis will also be placed on how we can manipulate list outputs and how this can be applied to our data.

Book: Functional Programming with purrr

Start Date:
Price:
Venue Details:
Time:
Duration:

Course Details

  • Course Outline
  • Learning Outcomes
  • Materials
  • Prior Knowledge

Course Outline

  • Introduction to {purrr} and Lists: Introduction to lists in R and using {purrr} to map a function across a list.
  • List-Columns and Nesting: Exploring nested data in list columns and using the mapping functions to manipulate them.
  • Parallel Mapping: Using {purrr} functions to map over multiple lists in parallel.
  • Manipulating {purrr} Output: Using {purrr} to efficiently extract elements from lists into vector and dataframe format, and change the hierarchy within nested lists.
  • Best Practices in {purrr}: Showcase of functions from {purrr} which aid in the debugging process.

Learning Outcomes

Session 1:

By the end of session 1, participants will be able to…

  • understand lists in R and know how to use {purrr} to map functions.
  • know what nested loops are and use {magrittr} to extract elements from them.
  • be able to create list columns and know how to access the data in them.

Session 2:

By the end of session 2, participants will be able to…

  • iteratively loop two or more objects to a function of choice using functions such as map2(), pmap() and imap().
  • recognize the advantages of using {purrr}.
  • understand how to extract elements from nested lists to achieve a desired output object class.
  • be able to effectively debug their code using multiple {purrr} functions for the debugging process.
  • save precious debugging time using e.g. safely()

This course does not include:

  • The {stringr} package, also from the {tidyverse} which helps with splitting and combining strings, manipulating text data and working with regular expressions. Jumping Rivers run a Text Mining in R course which covers {stringr} in detail.

No in-depth coverage of the tidyverse data visualisation package {ggplot2}, see our course on this for more information.

Materials

  • Page 1 of example course material for Functional Programming with purrr
  • Page 2 of example course material for Functional Programming with purrr
  • Page 3 of example course material for Functional Programming with purrr
  • Page 4 of example course material for Functional Programming with purrr
  • Page 5 of example course material for Functional Programming with purrr

Prior Knowledge

This course assumes basic Tidyverse skills, so having attended Data Wrangling in the Tidyverse or equivalent is necessary. As this course involves iterative programming, basic familiarity with for loops may be helpful. You can learn about for loops on our Programming with R course.

Attendee Feedback