| arg_equal | R Documentation |
Checks whether two arguments are equal (arg_equal()) or not equal (arg_not_equal()).
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
)
x, x2 |
the objects to compare with each other. |
... |
other arguments passed to |
.arg, .arg2 |
the names of the objects being compared; used in the error message if triggered. Ignored if |
.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. |
Tests for equality are performed by evaluating whether isTRUE(all.equal(x, x2, ...)) is TRUE or FALSE.
Returns NULL invisibly if an error is not thrown.
all.equal()
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.