Skip to contents

Infix equality operator that resolves missing values instead of propagating them.

Usage

x %==% y

Arguments

x

(atomic vector)
The left-hand side values to compare.

y

(atomic vector)
The right-hand side values to compare.

Value

A logical vector of length max(length(x), length(y)). The result never contains NA.

Details

base::== returns NA whenever either operand is NA. %==% resolves those positions and never returns NA.

For each pair of compared elements the result is

  • TRUE when both x and y are NA.

  • FALSE when exactly one of x and y is NA.

  • The value of x == y when neither is NA.

NaN is treated the same as NA, because is.na(NaN) is TRUE. NaN %==% NaN is TRUE and NaN %==% NA is TRUE.

x and y are recycled to a common length following standard R rules.

Examples

#----------------------------------------------------------------------------
# %==% examples
#----------------------------------------------------------------------------
library(bkbase)

# both NA gives TRUE, exactly one NA gives FALSE
1:3 %==% c(1:2, NA)   # TRUE TRUE FALSE
#> [1]  TRUE  TRUE FALSE
NA %==% NA            # TRUE
#> [1] TRUE

# NaN is treated the same as NA
1:3 %==% c(1:2, NaN)  # TRUE TRUE FALSE
#> [1]  TRUE  TRUE FALSE
NaN %==% NaN          # TRUE
#> [1] TRUE
NaN %==% NA           # TRUE
#> [1] TRUE

# base `==` propagates NA instead
1:3 == c(1:2, NA)     # TRUE TRUE NA
#> [1] TRUE TRUE   NA
1:3 == c(1:2, NaN)    # TRUE TRUE NA
#> [1] TRUE TRUE   NA