null-default {infixit} | R Documentation |
Default NULL operator
Description
This operator is seen in {rlang}
and has been included
in base R since version 4.4.0. If the left-hand side
is NULL, it will automatically return the value of
the right-hand side. This is useful for programming
to ensure a function or process returns a non-null
default.
Usage
x %||% y
Arguments
x |
The left-hand side, the value(s) to be evaluated as either NULL or not. |
y |
The right-hand side, the value(s) to be returned
if |
Value
An atomic value or vector the same length as the left-hand side input.
Examples
{
NULL %||% 'fizzbuzz' #returns fizzbuzz
'test' %||% 'fizzbuzz'#returns 'test'
}
[Package infixit version 0.3.1 Index]