| convoke | R Documentation |
convoke unifies functions along a single specification using
statements on function argument transformations that would be needed. The
result is a single function whose interface can be changed simply by
changing the respective argument in the generated function.
convoke(argslist, ...)
argslist |
[ |
... |
[ |
Function with additional class convoke with arguments being
convoke_func(specified_args, interface, ..., evaluate = TRUE)
The evaluate argument is useful for debugging purposes. Extra arguments can
be passed in the format interface.arg.
The unifying interface needs to be specified as arglist for the new function
list(arg1 = default1, arg2 = default2, etc.)
Transformations follows the function specification format
func1(func1arg1 = transformed_arg1, func1arg2 = transformed_arg2)
Essentially, pass the function as if it is to take arguments from the unified function.
It is also possible to progressively add functions to a convoke function simply by adding to the convoke function the new specifications:
convoke_func + ~func_spec
Other function assemblers:
conflate()
# unifying functions with swapped arguments
foo <- function(a1, b1) {
a1 / b1
}
bar <- function(b2, a2) {
a2 / b2
}
convoked <- convoke(
list(a, b),
foo(a1 = a, b1 = b),
bar(b2 = b, a2 = a)
)
c(convoked(9, 5), bar(5, 9))
c(convoked(9, 5, interface = "bar"), foo(9, 5))
# supplying optional arguments
foo <- function(a1, b1, round = FALSE) {
if (round) round(a1 / b1) else a1 / b1
}
bar <- function(b2, a2) {
a2 / b2
}
convoked <- convoke(
list(a, b),
foo(a1 = a, b1 = b),
bar(b2 = b, a2 = a)
)
c(convoked(9, 5, foo.round = FALSE), bar(5, 9))
c(convoked(9, 5, foo.round = TRUE), round(bar(5, 9)))
# TODO fix and show this for three sequences
# adding further functions later
foo <- function(a1, b1) {
a1 / b1
}
bar <- function(b2, a2) {
a2 / b2
}
(convoked <- convoke(list(a, b), foo(a1 = a, b1 = b)))
(convoked <- convoked + ~ bar(b2 = b, a2 = a))
c(convoked(9, 5, interface = "bar"), foo(5, 9))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.