grapes-eq-grapes: Check equality of two objects

%eq%R Documentation

Check equality of two objects

Description

The goal of the %eq% operator is to return a TRUE or FALSE value when any two objects are compared. The function provides a simple, reliable equality check that allows comparing of NULLs, NA values, and atomic data types without error.

The function also allows comparing of data frames. It will return TRUE if all values in the data frames are equal, and ignores differences in attributes.

Usage

x1 %eq% x2

Arguments

x1

The first object to compare

x2

The second object to compare

Value

A single TRUE or FALSE value depending on whether the objects are equal.

Examples

# Comparing of NULLs and NA
NULL %eq% NULL        # TRUE
NULL %eq% NA          # FALSE
NA %eq% NA            # TRUE
1 %eq% NULL           # FALSE
1 %eq% NA             # FALSE

# Comparing of atomic values
1 %eq% 1              # TRUE
"one" %eq% "one"      # TRUE
1 %eq% "one"          # FALSE
1 %eq% Sys.Date()     # FALSE

# Comparing of vectors
v1 <- c("A", "B", "C")
v2 <- c("A", "B", "D")
v1 %eq% v1            # TRUE
v1 %eq% v2            # FALSE

# Comparing of data frames
mtcars %eq% mtcars    # TRUE
mtcars %eq% iris      # FALSE
iris %eq% iris[1:50,] # FALSE

# Mixing it up
mtcars %eq% NULL      # FALSE
v1 %eq% NA            # FALSE
1 %eq% v1             # FALSE


common documentation built on May 29, 2024, 1:48 a.m.