extended-null-default {infixit} | R Documentation |
Expanded default operator
Description
The %||%
operator will return a default value,
defined by the right-hand object, if the left-hand value
resolves as NULL
. However, there may be times when users
want more than just NULL
values to return the default but,
also, values that are NA
, FALSE
, and those that are
length 0 (such as character(0)
or integer(0)
).
Usage
lhs %|||% rhs
Arguments
lhs |
The left-hand side, the value(s) to be evaluated as. |
rhs |
The right-hand side, the value(s) to be returned
if |
Details
The expanded default operator covers the following cases:
-
NULL
An atomic
FALSE
A vector where all values are
FALSE
An atomic
NA
A vector where all values are
NA
An object of length 0.
Users have the ability to add additional tests via
options(infixit.extended_default_tests)
. Users can change
the current list—including by adding the name of a testing
function (i.e., one that returns a Boolean value) that is
currently defined in an environment accessible to the function
(e.g., in the global environment).
Value
An atomic value or vector the same length as the left-hand side input.
Examples
{
NULL %|||% 'fizzbuzz' #returns fizzbuzz
FALSE %|||% 'fizzbuzz' #also returns fizzbuzz
NA %|||% 'fizzbuzz' #still returns fizzbuzz
'test' %|||% 'fizzbuzz'#returns 'test'
}