add_call_callback {foolbox} | R Documentation |
Add a function-specific callback to the call callbacks.
Description
This function adds to the existing call callback, rather than replace it, by putting a callback in front of it to be tested first. The callback will be invoked when the traversal sees a call to a specific function.
Usage
add_call_callback(callbacks, fn, cb)
Arguments
callbacks |
The existing callbacks. |
fn |
The function to which calls should be modified. |
cb |
The callback function to invoke. |
Details
The callback that is installed will be called with the usual callback
arguments (which depend on context and user-provided information to
..., see rewrite_callbacks()
and analysis_callbacks()
), and additionally
the next callback in line, through the parameter next_cb
. This can be
used to propagate information through several callbacks in a pipe-like
fashion.
Value
The updated callbacks.
Examples
f <- function(x) 2 + x
cb <- rewrite_callbacks() %>%
add_call_callback(f, function(expr, ...) {
quote(2 + x)
})
tr_f <- . %>% rewrite() %>% rewrite_with(cb)
g <- function(y) y + f(y)
tr_f(g)
[Package foolbox version 0.1.1 Index]