arg_equal: Check Equal Arguments

View source: R/arg_equal.R

arg_equalR Documentation

Check Equal Arguments

Description

Checks whether two arguments are equal (arg_equal()) or not equal (arg_not_equal()).

Usage

arg_equal(
  x,
  x2,
  ...,
  .arg = rlang::caller_arg(x),
  .arg2 = rlang::caller_arg(x2),
  .msg = NULL,
  .call
)

arg_not_equal(
  x,
  x2,
  ...,
  .arg = rlang::caller_arg(x),
  .arg2 = rlang::caller_arg(x2),
  .msg = NULL,
  .call
)

Arguments

x, x2

the objects to compare with each other.

...

other arguments passed to all.equal().

.arg, .arg2

the names of the objects being compared; used in the error message if triggered. Ignored if .msg is supplied.

.msg

an optional alternative message to display if an error is thrown instead of the default message.

.call

the execution environment of a currently running function, e.g. .call = rlang::current_env(). The corresponding function call is retrieved and mentioned in error messages as the source of the error. Passed to err(). Set to NULL to omit call information. The default is to search along the call stack for the first user-facing function in another package, if any.

Details

Tests for equality are performed by evaluating whether isTRUE(all.equal(x, x2, ...)) is TRUE or FALSE.

Value

Returns NULL invisibly if an error is not thrown.

See Also

all.equal()

Examples

f <- function(x, y, ...) {
  arg_equal(x, y, ...)
}

try(f(x = 1, y = 1))      ## No error
try(f(x = 1L, y = 1.0))   ## No error despite type difference
try(f(x = 1, y = 1.00001, ## No error, within tolerance
      tolerance = .001))

try(f(x = 1, y = 2))       ## Error: different
try(f(x = 1, y = 1.00001)) ## Error

g <- function(x, y, ...) {
  arg_not_equal(x, y, ...)
}

try(g(x = 1, y = 1)) ## Error
try(g(x = 1, y = 2)) ## No error

arg documentation built on April 9, 2026, 5:09 p.m.