logical_OR: Logical 'OR' operator

Description Usage Arguments Details Value References Examples

Description

Sets default values using a logical OR operator.

Usage

1
a %||% b

Arguments

a

NULL, or a particular 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

1
2
3
4
5
6
x <- NULL
x %||% 10              # => 10

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

toniprice/jutebag documentation built on May 12, 2019, 4:39 a.m.