set_defaults: Change the defaults of a function

Description Usage Arguments Value Examples

Description

The set_defaults function and the %<?% operator modifies the defaults of a function, returning a new function. As such it can be thought of as a soft partial application in that the arguments does not become fixed and the arity doesn't change, but the arguments can be ignored when making the final call.

Usage

1
2
3
set_defaults(fun, defaults)

fun %<?% defaults

Arguments

fun

A function whose argument default(s) should be changed

defaults

A named list of values. The values will be set as default for the arguments matching their name. Non-matching elements will be ignored

Value

A new function with changed defaults

Examples

1
2
3
4
5
6
7
testfun <- function(x = 1, y = 2, z = 3) {
  x + y + z
}
testfun()

testfun2 <- testfun %<?% list(y = 10)
testfun2()

thomasp85/curry documentation built on May 31, 2019, 11:12 a.m.