rewrites: Object for setting up a transformation pipeline when defining...

Description Usage Format Examples

Description

Object for setting up a transformation pipeline when defining functions

Usage

1

Format

An object of class foolbox_rewrite_spec of length 1.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# This is a very simple inline function that require we
# provide the function body as it should be inserted.
# For a more detailed version, see the Tutorial vignette.
# For a version that permits partial evaluation, see that vignette.
inline <- function(f, fn, body) {
   body <- substitute(body)
   rewrite(f) %>%
     rewrite_with(
         rewrite_callbacks() %>%
           add_call_callback(fn, function(expr, ...) body)
     )
}

g <- function(x) x**2
h <- rewrites[inline(g,y**2)] < function(y) y + g(y)
h

mailund/foolbox documentation built on Jan. 18, 2022, 10:46 a.m.