| orifnull | R Documentation |
Specify a value together with a default to be used when the first value is null.
a %orifnull% b
a |
Any kind of object or expression to be evaluated. |
b |
Default value to be used when |
The operator %orifnull% is designed to improve the
readability of code.
a %orifnull% b is equivalent to if(is.null(a)) a else b.
That is, a %orifnull% b is equal to
a provided a is not null, and otherwise
the result is equal to b.
Expressions are evaluated only when necessary.
If a is a language expression, it is first evaluated. Then if
is.null(a) is FALSE, the result is a. Otherwise,
b is evaluated, and the result is b.
Note that b is not evaluated unless a is NULL.
The operator %orifnull% has higher precedence than the arithmetic
operators +, -, *, / but lower precedence than ^.
The operator is associative, and can be used repeatedly in an expression, so that a default value may have its own default. See the Examples.
The result is a if a is not NULL,
and otherwise the result is b.
x <- 7
y <- 42
z <- w <- NULL
x %orifnull% y
z %orifnull% y
z %orifnull% x %orifnull% y
z %orifnull% w %orifnull% y
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.