Last data update: 2014.03.03

R: Return the first argument passed (out of any number) that is...
NVLR Documentation

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.

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.

Value

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

See Also

is.null, if

Examples

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

Results