A introduction to purrr
This repo hosts the materials for a purrr tutorial. The materials currently reflect the version planned for the useR! Brussels, Belgium, July 2017.
Older versions of the materials, from prior in-person tutorials, are also available:
Code with a lot of duplication is harder to understand, troubleshoot and maintain. The goal of this tutorial is help you remove duplication in your code by using functions that write
forloops for you.
You'll learn to use the functions in the
purrrpackage to perform iterative tasks: tasks that look like "for each _____ do _____".
By the end of the tutorial you'll be writing code that is more readable and easier to update and you'll be ready to solve new iteration problems faster and with fewer mistakes.
By the end of the tutorial, you'll be able to:
map().
map():
map_lgl(),
map_int(),
walk()etc.
map2().
purrrto get list data into tibbles.
purrrto work with list columns in tibbles.
Don't worry if you have never written a
forloop, used
lapply(), written your own function or heard of a
tibble, this tutorial is designed to be accessible to beginners.
That said, you should be familiar with exploring and subsetting the basic data structures in R including lists and data frames.
This is a hands-on tutorial, you'll need your laptop with R installed, as well as a few packages:
install.packages("tidyverse")install.packages("devtools")
devtools::install_github("jennybc/repurrrsive")
This purrr tutorial by Charlotte Wickham is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.