If-NULL-or-length-is-0: [.] Infix operator %if_null_or_len0%

Description Usage Arguments Value Examples

Description

The operator is useful as a way of providing a default value in case the output of another function is NULL or its length is zero.

Usage

1
a %if_null_or_len0% b

Arguments

a

An expression.

b

An alternative.

Value

If !is.null(a) & length(a) > 0 & nchar(a) > 0 is TRUE returns a, otherwise returns b.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
a1 <- "Default value"
a2 <- NULL
a3 <- character()
b  <- "Alternative"

 a1 %if_null_or_len0% b
#> [1] "Default value"

 a2 %if_null_or_len0% b
#> "Alternative"

 a3 %if_null_or_len0% b
#> "Alternative"

GegznaV/spTMP documentation built on May 6, 2019, 6:07 p.m.