op-zero-length: Operator Providing Alternative to Zero-Length Object

op-zero-lengthR Documentation

Operator Providing Alternative to Zero-Length Object

Description

Infix function implementing provision of an alternative if an object has zero length.

Usage

x %L% y

Arguments

x, y

atomic vector arguments or other objects for which length() is defined.

Details

The infix function %L% may be useful in implementing if (length(x)) x else y and was inspired by the null coalescing operator %||%.

Value

x, or if length(x) is zero, y.

See Also

%||%.

Examples

c4 <- letters[1:4]
c0 <- character(0)
n3 <- 1:3
n0 <- numeric(0)

c4 %L% n3
c0 %L% n3

n3 %L% c4
n0 %L% c4

rm(c4, c0, n3, n0)

Waypoint documentation built on April 11, 2025, 6:12 p.m.