Handbook for the afp
R Package
March 21, 2020 (Last updated: August 08, 2020)
Introduction
The afp
–Applied Functional Programming–package provides functionals to simplify iterative processes in R. The Base R *apply()
family, purrr
1 library, and Julia programming language2 are the principal influences. The former two contain tools essential for functional programming that minimize the need to incorporate loops and increase code brevity; however, there is inelegance with respect to specific situations.
For example, to map a function and consequently bind rows or columns, purrr
splits the decision into two functions rather than within one: map_dfr()
and map_dfc()
3, both of which only output to data frames (the former behaves the same as map_df()
4)–while this feature is as intended, they nonetheless omit the possibility of a matrix when such a data type is preferred. Additionally, to reduce the results of a mapping, one must encase Map()
/lapply()
in Reduce()
, while Julia blends the routine into mapreduce()
5.
As such, afp
exists to supplement the functionals in Base R,
purrr
, and others to support efficient and concise programming.
This handbook shows how to install afp
, followed by descriptions of each function in the package before concluding.
Type
purrr::map_df
in the console and compare withpurrr::map_dfr
.↩︎https://docs.julialang.org/en/v0.6.1/stdlib/collections/#Base.mapreduce-NTuple%7B4,Any%7D↩︎