Learn R Programming

statnet.common (version 3.2.3)

NVL: Return the first argument passed (out of any number) that is not NULL.

Description

This function is inspired by SQL function NVL, and simply returns the first argument that is not NULL, or NULL if all arguments are NULL.

Usage

NVL(...)

Arguments

...
Expressions to be tested.

Value

  • The first argument that is not NULL, or NULL if all are.

Details

Note that an earlier version of this function took only two arguments: EXPR, that was tested and returned if not NULL and NULLV, which was returned if EXPR was NULL. The new version produces identical output for the same (two-argument) input, but tests any number of expressions sequentially.

See Also

is.null, if

Examples

Run this code
a <- NULL

print(a) # NULL
print(NVL(a,0)) # 0

b <- 1

print(b) # 1
print(NVL(b,0)) # 1

# Also,
print(NVL(NULL,1,0)) # 1
print(NVL(NULL,0,1)) # 0
print(NVL(NULL,NULL,0)) # 0
print(NVL(NULL,NULL,NULL)) # NULL

Run the code above in your browser using DataLab