iff {arpr} | R Documentation |
Apply a function depending on test output
Description
iff
returns output of the function if and only if test is TRUE
.
iffn
returns output of the function if and only if test is FALSE
.
They return the original value otherwise.
iffelse
returns output of the first function if test is TRUE
,
output of the second function otherwise.
Usage
iff(obj, test, fun, ...)
iffn(obj, test, fun, ...)
iffelse(obj, test, true_fun, false_fun, ...)
Arguments
obj |
object to apply test and fun to |
test |
logical or function to apply to test |
fun |
function to apply |
... |
passed on to test |
true_fun |
function to apply when test is true |
false_fun |
function to apply when test is false |
Value
Output of function fun
applied to the original value or the
original value, depending on the test.
Examples
x <- 1
x %>%
iff(is.na, const(0))
x <- NA
x %>%
iff(is.na, const(0))
x <- 1
x %>%
iff(x <= 0, function(x) { x - 2 })
x <- -1
x %>%
iff(x <= 0, function(x) { x - 2 })
x <- NA
x %>%
iffn(is.na, exp)
x <- 10
x %>%
iffn(is.na, exp)
[Package arpr version 0.1.2 Index]