functools
provides tools for Functional Programming in R. It accomplishes several goals:
-
Add support to the usual higher order functional suspects (
Filter()
,Map()
,Reduce()
, etc.) with higher order functions (Compose()
,Memoise()
,Partial()
,Reject()
,Fail_With()
,Reduce_Right()
,All()
,Any()
, andBest()
). -
Supply higher order function generators (
Andify()
andOrify()
) to make composing predicate functions easier. -
Provide wrappers (
Apply()
,Lapply()
,Mapply()
,Sapply()
,Tapply()
, andVapply()
) around their respective base R functionals to create an API with consistent naming convention, positional arguments, and argument names. -
Implement common constants as functions (
True()
,False()
,Identity()
,Null()
, andNa()
) for point-free programming. -
Extend abstract concepts of existiness and truthiness through functions (
Existy()
andTruthy()
).
functools achieves these goals through three main types of function design patterns:
-
Closures (functions that take data and return functions)
-
Functionals (functions that take functions and return data)
-
Function Operators (functions that take functions and return functions)
You can install the latest development version from CRAN:
install.packages("functools")
Or from GitHub with:
if (packageVersion("devtools") < 1.6) {
install.packages("devtools")
}
devtools::install_github("paulhendricks/functools")
If you encounter a clear bug, please file a minimal reproducible example on GitHub.
To cite package ‘functools’ in publications use:
Paul Hendricks (2015). functools: Functional Programming in R. R package version 0.2.0. https://CRAN.R-project.org/package=functools
A BibTeX entry for LaTeX users is
@Manual{,
title = {functools: Functional Programming in R},
author = {Paul Hendricks},
year = {2015},
note = {R package version 0.2.0},
url = {https://CRAN.R-project.org/package=functools},
}