make_opt {optional} | R Documentation |
Make optional
Description
Make an existing function accepting and returning optionals.
Usage
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, |
fun_if_none |
If not null, will be executed if an argument
is |
Details
Every optional argument passed to
f_opt()
will be converted to its original type before being sent tof()
. If one or more of them isnone
, several behaviors are available (see argument list).If
f()
returns null, or if an error is thrown during its execution, thenf_opt()
returnsnone
. Else it will returnoption(f(...))
.
Value
The optional function. To be used with the
same parameters than fun()
.
See Also
option(), none(), match_with()
Examples
c_opt <- make_opt(c)
c_opt(option(2), none, option(5))
## [1] 2 5
c_opt()
## [1] "None"