Description Usage Arguments Details Value References Examples
Sets default values using a logical OR
operator.
1 | a %||% b
|
a |
NULL, or a particular 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.
1 2 3 4 5 6 | x <- NULL
x %||% 10 # => 10
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.