iff {arpr}R Documentation

Apply a function if and only if test is TRUE

Description

otherwise return input value unchanged

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

Details

iffn is ... if and only if test is FALSE

Examples

require(magrittr)
x <- sample(c(1,2,NA), 1)
x <- x %>%
  iff(is.na, const(0))
y <- x%>%
  iff(x <= 0, function(x) { x - 2 })

x <- sample(c(1,2,NA), 1)
x %>%
  iffn(is.na, exp)


[Package arpr version 0.1.1 Index]