NVL: Convenience functions for handling 'NULL' objects.

Description Usage Arguments Functions Note See Also Examples

View source: R/misc.utilities.R

Description

Convenience functions for handling NULL objects.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
NVL(...)

NVL2(test, notnull, null = NULL)

NVL3(test, notnull, null = NULL)

EVL(...)

EVL2(test, notnull, null = NULL)

EVL3(test, notnull, null = NULL)

NVL(x) <- value

EVL(x) <- value

Arguments

..., test

expressions to be tested.

notnull

expression to be returned if test is not NULL.

null

expression to be returned if test is NULL.

x

an object to be overwritten if NULL.

value

new value for x.

Functions

Note

Whenever possible, these functions use lazy evaluation, so, for example NVL(1, stop("Error!")) will never evaluate the stop call and will not produce an error, whereas NVL(NULL, stop("Error!")) would.

See Also

NULL, is.null, if

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
a <- NULL

a # NULL
NVL(a,0) # 0

b <- 1

b # 1
NVL(b,0) # 1

# Here, object x does not exist, but since b is not NULL, x is
# never evaluated, so the statement finishes.
NVL(b,x) # 1

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

NVL2(a, "not null!", "null!") # "null!"
NVL2(b, "not null!", "null!") # "not null!"

NVL3(a, "not null!", "null!") # "null!"
NVL3(b, .+1, "null!") # 2

NVL(NULL*2, 1) # numeric(0) is not NULL
EVL(NULL*2, 1) # 1


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

Example output

sh: 1: cannot create /dev/null: Permission denied

Attaching package:statnet.commonThe following object is masked frompackage:base:

    order

NULL
[1] 0
[1] 1
[1] 1
[1] 1
[1] 1
[1] 0
[1] 0
NULL
[1] "null!"
[1] "not null!"
[1] "null!"
[1] 2
numeric(0)
[1] 1
[1] 2
[1] 1

statnet.common documentation built on June 5, 2021, 5:06 p.m.