Learn R Programming

fuj (version 0.2.1)

if_null: Default value for NULL or no length

Description

Replace if NULL or not length

Usage

x %||% y

x %|||% y

x %len% y

Value

x if it is not NULL or has length, depending on check

Arguments

x, y

If x is NULL returns y; otherwise x

Details

A mostly copy of rlang's %||% except does not use rlang::is_null(), which, currently, calls the same primitive base::is.null function.

Note: %||% is copied from {base} if available (R versions >= 4.4)

Examples

Run this code
# replace NULL (for R < 4.4)
NULL %||% 1L
2L   %||% 1L

# replace empty
""       %|||% 1L
NA       %|||% 1L
double() %|||% 1L
NULL     %|||% 1L

# replace no length
logical() %len% TRUE
FALSE     %len% TRUE

Run the code above in your browser using DataLab