Eugene Ha
2018-Jun-02 21:30 UTC
[R-pkgs] gestalt: Tools for Making and Combining Functions
Dear R Users, The gestalt package (0.1.1) has been published on CRAN: https://cran.r-project.org/package=gestalt It provides a suite of function-building tools centered around a (forward) composition operator, '%>>>%', which extends the semantics of the magrittr '%>%' operator and supports tidyverse quasiquotation. Aside from making your functions more modular, the main benefit of '%>>>%' is its ability to make composite functions that can be inspected and transformed as list-like objects. As an illustration, you can sample, capitalize, and join (character) vectors with the following composite function: draw <- sample %>>>% toupper %>>>% paste(collapse = "") set.seed(1) draw(letters, 5) #> [1] ?GJNUE" But because the composite function 'draw()' is list-like, you can also inspect its intermediate results using a standard map-reduce strategy: stepwise <- lapply(`%>>>%`, print) %>>>% compose set.seed(1) stepwise(draw)(letters, 5) #> [1] "g" "j" "n" "u" "e" #> [1] "G" "J" "N" "U" "E" #> [1] "GJNUE" In conjunction with '%>>>%', a compact function constructor, 'fn()', and a function that performs partial application, 'partial()', are also provided. Both support quasiquotation. Learn more from - the landing page of the source repository: https://github.com/egnha/gestalt - the package vignette, which gives an overview through examples: https://cran.r-project.org/package=gestalt/vignettes/gestalt.html Bug reports and other feedback are welcome at the GitHub issues page: https://github.com/egnha/gestalt/issues Eugene Ha