op-nullish: The usual nullish operator

Description Usage Arguments Value Examples

Description

This operator returns y if and only if x is NULL. Otherwise, it returns x. It is most useful to provide alternatives in assignment operations. See examples.

Usage

1
x %||% y

Arguments

x, y

[any]

R Objects.

Value

Either x or y. The latter is returned if and only if x is NULL.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## Assign an object to a name, and provide an alternative if it is NULL.
a <- 1L
b <- 2L
c <- a %||% b

identical(c, a) # TRUE

a <- NULL
c <- a %||% b

identical(c, b) # TRUE

jeanmathieupotvin/dotprofile documentation built on Dec. 20, 2021, 10:08 p.m.