logical_OR | R Documentation |
OR
operatorSets default values using a logical OR
operator.
a %||% b
a |
NULL, or a specific value. |
b |
The default value to return if the first operand is NULL. |
This infix function is inspired by Ruby's "logical OR" operator (||
)
for conveniently setting default values.
usage:
function_that_might_return_null() %||% <default value>
See Advanced R (Hadley Wickham) Section 6.5.1 p. 91.
A non-NULL value. This is is the value of the first operand if it is non-NULL, or the value of the second operand if the first operand is NULL.
Wickham, Hadley (2015). Advanced R, CRC Press, Boca Raton FL.
x <- NULL x %||% 10 # => 10 x <- NULL y <- "Nelson Mandela" x %||% y # => 'Nelson Mandela' x <- "Madiba" y <- "Nelson Mandela" x %||% y # => 'Madiba'
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.