logical_OR: Logical 'OR' operator

logical_ORR Documentation

Logical OR operator

Description

Sets default values using a logical OR operator.

Usage

a %||% b

Arguments

a

NULL, or a specific value.

b

The default value to return if the first operand is NULL.

Details

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.

Value

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.

References

Wickham, Hadley (2015). Advanced R, CRC Press, Boca Raton FL.

Examples

x <- NULL
x %||% 10 # => 10

x <- NULL
y <- "Nelson Mandela"
x %||% y # => 'Nelson Mandela'

x <- "Madiba"
y <- "Nelson Mandela"
x %||% y # => 'Madiba'


toniprice/jute documentation built on Jan. 11, 2023, 8:23 a.m.