If-is-NULL: Infix operator to insert default value if result is NULL

Description Usage Arguments Value Examples

Description

The function is useful as a way of providing a default value in case the output of another function is NULL.

Usage

1
a %if.NULL% b

Arguments

a

An expression.

b

An alternative

Value

If !is.null(a) 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
b  <- "Alternative"


## Not run: 
 a1 %if.NULL% b
#> [1] "Default value"

 a2 %if.NULL% b
#> "Alternative"

## End(Not run)

GegznaV/spMisc documentation built on April 26, 2020, 5:59 p.m.