[R-pkgs] gestalt: Tools for Making and Combining Functions
Eugene Ha
eh@ @ending from po@teo@de
Sat Jun 2 23:30:45 CEST 2018
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
More information about the R-packages
mailing list