Learn R Programming

statnet.common (version 4.0.0)

NVL: Convenience functions for handling NULL objects.

Description

Convenience functions for handling NULL objects.

Usage

NVL(...)

NVL(x) <- value

Arguments

Expressions to be tested.

x

an object to be overwritten if NULL.

value

new value for x.

Functions

  • NVL: Inspired by SQL function NVL, NVL(...) returns the first argument that is not NULL, or NULL if all arguments are NULL.

  • NVL<-: Assigning to NVL overwrites its first argument if that argument is NULL. Note that it will always return the right-hand-side of the assignment (value), regardless of what x is.

See Also

NULL, is.null, if

Examples

Run this code
# NOT RUN {
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

NVL(a) <- 2
a # 2
NVL(b) <- 2
b # still 1
# }

Run the code above in your browser using DataLab