A functional programming toolkit for R that enhances data manipulation with consistent, type-stable functions for working with vectors and lists.
purrr is an R package that provides a functional programming toolkit for working with vectors and lists. It enhances R's capabilities by offering a consistent set of functions like `map()` to replace for loops, making code more succinct and easier to read. It solves the problem of repetitive iteration and data manipulation tasks in R.
R developers and data scientists, particularly those working within the tidyverse ecosystem, who need to perform iterative operations on data structures like lists and vectors.
Developers choose purrr for its type-stable functions, seamless integration with the pipe operator, and flexibility in handling different input types. Its consistent API and support for progress tracking and parallel processing make it a robust alternative to base R loops.
A functional programming toolkit for R
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
All map functions return predictable types; for example, map() always outputs a list, and map_dbl() ensures a double vector, reducing runtime errors as highlighted in the README's comparison to base R.
The first argument is always data, making it natural to use with the pipe operator (|>), enabling readable pipelines like in the mtcars example for fitting models across groups.
map() accepts functions, character vectors for name-based extraction, or numeric vectors for position-based extraction, offering versatile ways to apply operations without boilerplate code.
Built-in .progress argument for tracking long jobs and compatibility with in_parallel() for easy multi-core or distributed computing, as mentioned in the README's key features.
Using purrr often encourages dependency on other tidyverse packages, which can bloat projects if only functional programming tools are needed, limiting flexibility in lean environments.
Functional calls may introduce slight overhead compared to highly optimized base R vectorized operations, especially for large datasets where loops or apply functions might be more efficient.
Requires understanding of functional programming concepts, which can be a barrier for R users accustomed to imperative loops, as the README notes it's best learned from external resources like R for Data Science.