Tools for Making and Combining Functions

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. It enables you to construct composite functions that can be inspected and transformed as list-like objects. In conjunction with %>>>%, a compact function constructor, fn(), and a function that performs partial application, partial(), are also provided. Both support quasiquotation.


News

gestalt

0.1.6

This is a maintenance release to fix test failures caused by changes in the rlang package.

  • The (minimum) required rlang version has been increased to 0.3.1. This version fixed a bug which prevented certain operator "sections" from being expressed. A chain like `/`(2) %>>>% sin (halve and apply sine) now works as expected.

  • Formals of primitive functions now agree with those of base::args() (#18, #24). This means you can use args() to determine the names of arguments when using partial(). Thus, partial(`/`, e2 = 3) is the same as partial(`/`, , 3) is the same as division-by-3. Moreover, %>>>% chains are verified against the argument names given by args(). Thus, `/`(e2 = 2) %>>>% sin is valid, but `/`(y = 2) %>>>% sin is invalid—`/`() viewed as a closure has no argument called y.

  • Support for R 3.1 has been dropped.

0.1.5

  • Fixed a segfault caused by leakage of rlang internals (thanks @lionel-).

  • names() now gets the names of bindings in a context (as made by let()).

0.1.4

New features

  • posure() is a means of creating efficient variable (i.e., parameterized) composite functions.

    In particular, this addresses a shortcoming of the use of the magrittr %>% in functions. Instead of writing

    function(..., b = 2, n) {
      sample(...) %>% log(base = b) %>% rep(n)
    }
    

    which is inefficient because the function chain is created anew with each call, you can more directly curry it by writing

    posure(b = 2, n ~ {
      sample %>>>% log(base = b) %>>>% rep(n)
    })
    

    Not only is the posure() version more succinct, it is robuster and faster than the version with %>%, thanks to the non-standard mechanism of a closure that is “partially dynamically scoped.” (Whence the portmanteau “posure,” due to @henryaj; see the package documentation for details.)

  • let() enables you to create contexts: composable local environments in which named expressions are lazily resolved in a given order. Tidyverse quasiquotation of expressions is supported, allowing you to exercise fine-grained control over the evaluation of subexpressions.

  • As a companion to let(), run() evaluates an expression relative to a context. Unlike base::with(), run() supports quasiquotation and provides a means of overriding bindings in a given context.

Minor improvements

  • When calling a composite function, the point (.) in an implicitly curried function may now assume any name (#10). This is useful when you want to call the argument assumed by the point by its original name, e.g., in a do.call() or lapply() invocation.

  • partial() is now literally interpreted by %>>>% (#11). For instance, you you can succinctly write abs %>>>% partial(log, base = 2) instead of abs %>>>% !!partial(log, base = 2).

0.1.2

  • In a composite function, default argument values following ... are no longer absorbed by ... (#6).

  • Improvements to the documentation throughout.

0.1.1

  • Initial release.

  • fn() is extracted from nofrills 0.3.0.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("gestalt")

0.1.6 by Eugene Ha, 2 months ago


https://github.com/egnha/gestalt


Report a bug at https://github.com/egnha/gestalt/issues


Browse source code at https://github.com/cran/gestalt


Authors: Eugene Ha [aut, cre]


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports rlang, utils

Suggests magrittr, dplyr, testthat, knitr, rmarkdown


See at CRAN