partial: Partially apply a function

Description Usage Arguments Author(s) References See Also Examples

View source: R/partial.R

Description

Simplify a function by setting some arguments to pre-specified values

Usage

1

Arguments

f

a function

...

arguments to capture

Author(s)

John Silberholz, A Webb

References

http://stackoverflow.com/questions/32173901/how-to-efficiently-partially-apply-a-function-in-r, https://stackoverflow.com/a/31900149/986793

See Also

partial

Curry

Examples

1
2
3
4
5
6
7
8
# Example 1:
f <- function(a, b, c, d) a+b+c+d
p <- partial(f, a=2, c=3)
p(b=0, d=1)

# captures a format string for printing out sleep data
labeller <- partial(sprintf, fmt="extra=%3.2f, group=%d, ID=%d")
do.call(labeller, sleep[1, , drop=FALSE])

stackoverflow documentation built on Jan. 10, 2020, 9:07 a.m.