null-default | R Documentation |
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.
x %||% y
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 |
An atomic value or vector the same length as the left-hand side input.
{
NULL %||% 'fizzbuzz' #returns fizzbuzz
'test' %||% 'fizzbuzz'#returns 'test'
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.