op-na-default: Replace missing values

op-na-defaultR Documentation

Replace missing values

Description

Note: This operator is now out of scope for rlang. It will be replaced by a vctrs-powered operator (probably in the funs package) at which point the rlang version of ⁠%|%⁠ will be deprecated.

This infix function is similar to %||% but is vectorised and provides a default value for missing elements. It is faster than using base::ifelse() and does not perform type conversions.

Usage

x %|% y

Arguments

x

The original values.

y

The replacement values. Must be of length 1 or the same length as x.

See Also

op-null-default

Examples

c("a", "b", NA, "c") %|% "default"
c(1L, NA, 3L, NA, NA) %|% (6L:10L)

hadley/rlang documentation built on Dec. 17, 2024, 3:26 a.m.