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

Share:

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

1

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
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