extended-null-default | R Documentation |
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)
).
lhs %|||% rhs
lhs |
The left-hand side, the value(s) to be evaluated as. |
rhs |
The right-hand side, the value(s) to be returned
if |
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).
An atomic value or vector the same length as the left-hand side input.
{
NULL %|||% 'fizzbuzz' #returns fizzbuzz
FALSE %|||% 'fizzbuzz' #also returns fizzbuzz
NA %|||% 'fizzbuzz' #still returns fizzbuzz
'test' %|||% 'fizzbuzz'#returns 'test'
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.