ifElseMore: An 'ifelse()' handling NA and NULL too.

View source: R/missingValues.R

ifElseMoreR Documentation

An ifelse() handling NA and NULL too.

Description

Tests a Boolean scalar value and returns one of four values:

  • If x is TRUE, returns the value of the true parameter (TRUE by default).

  • If x is FALSE, returns the value of false parameter (FALSE by default).

  • If x is NA, returns the value of na parameter (NA by default).

  • If x is NULL, returns the value of null parameter (NULL by default).

Usage

ifElseMore(x, true = TRUE, false = FALSE, na = NA, null = NULL)

Arguments

x

The value to test

true

The value to return if x is TRUE. Returns TRUE by default.

false

The value to return if x is FALSE. Returns FALSE by default.

na

The value to return if x is NA. Returns NA by default.

null

The value to return if x is NULL. Returns NULL by default.

Value

Depending on the value of x, returns the values of the matching parameter true, false, na, or null.

Examples

ifElseMore( 3 > 2 )
#> [1] TRUE
ifElseMore( 3 < 2 )
#> [1] FALSE
ifElseMore( 3 < NA )
#> [1] NA

ifElseMore( 3 > 2, "it's True", "it's False", "it's NA", "it's Null" )
#> [1] "it's True"
ifElseMore( 2 > 3, "it's True", "it's False", "it's NA", "it's Null" )
#> [1] "it's False
ifElseMore( NA > 2, "it's True", "it's False", "it's NA", "it's Null" )
#> [1] "it's NA"

x <- NULL
ifElseMore( x )
#> [1] NULL
ifElseMore( x, "it's True", "it's False", "it's NA", "it's Null" )
#> [1] "it's Null"


jefferys/JefferysRUtils documentation built on Jan. 12, 2024, 9:18 p.m.