Execute a function if a predicate function returns TRUE. Intended for use with cli functions.
Usage
cli_if(
x = NULL,
...,
.predicate = rlang::is_true,
.fn = NULL,
.default = cli::cli_alert,
.envir = rlang::caller_env(),
call = rlang::caller_env()
)
cli_ifnot(
x = NULL,
...,
.predicate = rlang::is_false,
.fn = NULL,
.default = cli::cli_alert,
.envir = rlang::caller_env(),
call = rlang::caller_env()
)
Arguments
- x
Parameter to passed to .predicate function, Default:
NULL
- ...
Additional parameters passed to .fn.
- .predicate
Single parameter predicate function, Defaults to
rlang::is_true
forcli_if()
orrlang::is_false
forcli_ifnot()
. If .predicate returnsTRUE
, execute .fn. Aborts if .predicate does not return a boolean value.- .fn
Function to call with ... parameters if x, Default:
NULL
- .default
Default function to execute when .predicate function returns
TRUE
, Default:cli::cli_alert
- call
The execution environment of a currently running function, e.g.
caller_env()
. The function will be mentioned in error messages as the source of the error. See thecall
argument ofabort()
for more information.