identical2: Test two or more objects for exact equality

View source: R/zxx.R

identical2R Documentation

Test two or more objects for exact equality

Description

The safe and reliable way to test two or more objects for being exactly equal; returns TRUE in this case, FALSE in every other case.

Usage

identical2(
  ...,
  num.eq = TRUE,
  single.NA = TRUE,
  attrib.as.set = TRUE,
  ignore.bytecode = TRUE,
  ignore.environment = FALSE
)

Arguments

...

any R objects

num.eq

logical indicating if (double and complex non-NA) numbers should be compared using == ("equal"), or by bitwise comparison. The latter (non-default) differentiates between -0 and +0

single.NA

logical indicating if there is conceptually just one numeric NA and one NaN; single.NA = FALSE differentiates bit patterns

attrib.as.set

logical indicating if attributes of ... should be treated as unordered tagged pairlists ("sets"); this currently also applies to slots of S4 objects. It may well be too strict to set attrib.as.set = FALSE

ignore.bytecode

logical indicating if byte code should be ignored when comparing closures.

ignore.environment

logical indicating if their environments should be ignored when comparing closures.

Value

A single logical value, TRUE or FALSE, never NA and never anything other than a single value.

See Also

identical; all.equal for descriptions of how two objects differ; Comparison for operators that generate element-wise comparisons; isTRUE is a simple wrapper based on identical; all_equal2

Examples

identical2(1, 1.)
identical2(1, 1., 1L)

## for unusual R objects:
identical2(.GlobalEnv, environment(), globalenv(), as.environment(1))

identical2(0., 0, -0.) ## not differentiated
identical2(0., 0, -0., num.eq = FALSE)

identical2(NaN, -NaN)
identical2(NaN, -NaN, single.NA = FALSE) ## differ on bit-level

## for functions
f <- function(x) x
g <- compiler::cmpfun(f)
identical2(f, g)
identical2(f, g, ignore.bytecode = FALSE)


raredd/rawr documentation built on March 4, 2024, 1:36 a.m.