iff: Apply a function if and only if test is TRUE

Description Usage Arguments Details Examples

Description

otherwise return input value unchanged

Usage

1
2
3
4
5
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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)

arpr documentation built on May 2, 2019, 8:51 a.m.

Related to iff in arpr...