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.