[ RDocumentation ](/)

Moon  [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)

Search all packages and functions

[ base  (version  3.6.2  ) ](/packages/base/versions/3.6.2)

#  identical: Test Objects for Exact Equality

##  Description

The safe and reliable way to test two objects for being _exactly_ equal. It
returns ` TRUE ` in this case, ` FALSE ` in every other case.

##  Usage

    
    
    identical(x, y, num.eq = TRUE, single.NA = TRUE, attrib.as.set = TRUE,
              ignore.bytecode = TRUE, ignore.environment = FALSE,
              ignore.srcref = TRUE)

##  Arguments

x, y

any  R  objects.

num.eq

logical indicating if ( ` [ double ](/link/double?package=base&version=3.6.2)
` and ` [ complex ](/link/complex?package=base&version=3.6.2) ` non- ` [ NA
](/link/NA?package=base&version=3.6.2) ` ) numbers should be compared using `
[ == ](/link/%3D%3D?package=base&version=3.6.2) ` (‘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
](/link/NA?package=base&version=3.6.2) ` and one ` [ NaN
](/link/NaN?package=base&version=3.6.2) ` ; ` single.NA = FALSE `
differentiates bit patterns.

attrib.as.set

logical indicating if ` [ attributes
](/link/attributes?package=base&version=3.6.2) ` of ` x ` and ` y ` should be
treated as _unordered_ tagged pairlists (“sets”); this currently also applies
to ` [ slot ](/link/slot?package=base&version=3.6.2) ` s 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 [ closure
](/link/closure?package=base&version=3.6.2) s.

ignore.environment

logical indicating if their environments should be ignored when comparing [
closure ](/link/closure?package=base&version=3.6.2) s.

ignore.srcref

logical indicating if their ` "srcref" ` attributes should be ignored when
comparing [ closure ](/link/closure?package=base&version=3.6.2) s.

##  Value

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

##  Details

A call to ` identical ` is the way to test exact equality in ` if ` and `
while ` statements, as well as in logical expressions that use ` && ` or ` ||
` . In all these applications you need to be assured of getting a single
logical value.

Users often use the comparison operators, such as ` == ` or ` != ` , in these
situations. It looks natural, but it is not what these operators are designed
to do in  R  . They return an object like the arguments. If you expected ` x `
and ` y ` to be of length 1, but it happened that one of them was not, you
will _not_ get a single ` FALSE ` . Similarly, if one of the arguments is ` NA
` , the result is also ` NA ` . In either case, the expression ` if(x ==
y).... ` won't work as expected.

The function ` all.equal ` is also sometimes used to test equality this way,
but was intended for something different: it allows for small differences in
numeric results.

The computations in ` identical ` are also reliable and usually fast. There
should never be an error. The only known way to kill ` identical ` is by
having an invalid pointer at the C level, generating a memory fault. It will
usually find inequality quickly. Checking equality for two large, complicated
objects can take longer if the objects are identical or nearly so, but
represent completely independent copies. For most applications, however, the
computational cost should be negligible.

If ` single.NA ` is true, as by default, ` identical ` sees ` [ NaN
](/link/NaN?package=base&version=3.6.2) ` as different from ` [ NA_real_
](/link/NA_real_?package=base&version=3.6.2) ` , but all ` NaN ` s are equal
(and all ` NA ` of the same type are equal).

Character strings are regarded as identical if they are in different marked
encodings but would agree when translate