if_
conditionsif_none()
, if_any()
and
if_all()
test the elements of the list.
if_all(1:10, ~ .x < 11, ~ return(letters[1:10]))
#> [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j"
if_any(1:10, is.numeric, ~"Yay!")
#> [1] "Yay!"
if_none(1:10, is.character, ~ rnorm(10))
#> [1] -0.5836457 -0.7851794 -1.6050473 -1.8385780 -0.2583154 -0.7480809
#> [7] -0.3710978 0.3327126 -0.3829840 0.8685682
The defaut for all .p
is isTRUE()
. So you
can:
if_then()
performs a simple “if this then do that”:
if_not()
runs .f
if .p(.x)
is
not TRUE :
And if_else()
is a wrapper around
base::ifelse()
.
If you want these function to return a value, you need to wrap these
values into a mapper / a function. E.g, to return a vector, you’ll need
to write if_then(1, is.numeric, ~ "Yay")
.