make_opt: Make optional

Description Usage Arguments Details Value See Also Examples

View source: R/optional.R

Description

Make an existing function accepting and returning optionals.

Usage

1
make_opt(fun, stop_if_none = FALSE, fun_if_none = NULL)

Arguments

fun

The function to make optional, might be any function.

stop_if_none

If true, f_opt() will stop and return none if one of the arguments provided is none. Else, none will be sent as NULL to the function. *Default: FALSE*

fun_if_none

If not null, will be executed if an argument is none. *Default: NULL*

Details

  1. Every optional argument passed to f_opt() will be converted to its original type before being sent to f(). If one or more of them is none, several behaviors are available (see argument list).

  2. If f() returns null, or if an error is thrown during its execution, then f_opt() returns none. Else it will return option(f(...)).

Value

The optional function. To be used with the same parameters than fun().

See Also

option(), none(), match_with()

Examples

1
2
3
4
5
c_opt <- make_opt(c)
c_opt(option(2), none, option(5))
## [1] 2 5
c_opt()
## [1] "None"

optional documentation built on May 1, 2019, 9:14 p.m.