powered by
Infix function implementing provision of an alternative if an object has zero length.
x %L% y
x, or if length(x) is zero, y.
x
length(x)
y
atomic vector arguments or other objects for which length() is defined.
length()
The infix function %L% may be useful in implementing if (length(x)) x else y and was inspired by the null coalescing operator %||%.
%L%
if (length(x)) x else y
%||%
%||%.
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)
Run the code above in your browser using DataLab