[ 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)

#  all.equal: Test if Two Objects are (Nearly) Equal

##  Description

` all.equal(x, y) ` is a utility to compare  R  objects ` x ` and ` y `
testing ‘near equality’. If they are different, comparison is still made to
some extent, and a report of the differences is returned. Do not use `
all.equal ` directly in ` if ` expressions---either use `
isTRUE(all.equal(....)) ` or ` [ identical
](/link/identical?package=base&version=3.6.2) ` if appropriate.

##  Usage

    
    
    all.equal(target, current, …)
    
    # S3 method for numeric
    all.equal(target, current,
              tolerance = sqrt(.Machine$double.eps), scale = NULL,
              countEQ = FALSE,
              formatFUN = function(err, what) format(err),
              …, check.attributes = TRUE)
    
    # S3 method for list
    all.equal(target, current, …,
              check.attributes = TRUE, use.names = TRUE)
    
    # S3 method for environment
    all.equal(target, current, all.names=TRUE, …)
    
    # S3 method for POSIXt
    all.equal(target, current, …, tolerance = 1e-3, scale)
    
    
    attr.all.equal(target, current, …,
                   check.attributes = TRUE, check.names = TRUE)

##  Arguments

target

R  object.

current

other  R  object, to be compared with ` target ` .

…

further arguments for different methods, notably the following two, for
numerical comparison:

tolerance

numeric \\(\ge\\) 0. Differences smaller than ` tolerance ` are not reported.
The default value is close to ` 1.5e-8 ` .

scale

` NULL ` or numeric > 0, typically of length 1 or ` length(target) ` . See
‘Details’.

countEQ

logical indicating if the ` target == current ` cases should be counted when
computing the mean (absolute or relative) differences. The default, ` FALSE `
may seem misleading in cases where ` target ` and ` current ` only differ in a
few places; see the extensive example.

formatFUN

a ` [ function ](/link/function?package=base&version=3.6.2) ` of two
arguments, ` err ` , the relative, absolute or scaled error, and ` what ` , a
character string indicating the _kind_ of error; maybe used, e.g., to format
relative and absolute errors differently.

check.attributes

logical indicating if the ` [ attributes
](/link/attributes?package=base&version=3.6.2) ` of ` target ` and ` current `
(other than the names) should be compared.

use.names

logical indicating if ` [ list ](/link/list?package=base&version=3.6.2) `
comparison should report differing components by name (if matching) instead of
integer index. Note that this comes after ` … ` and so must be specified by
its full name.

all.names

logical passed to ` [ ls ](/link/ls?package=base&version=3.6.2) ` indicating
if “hidden” objects should also be considered in the environments.

check.names

logical indicating if the ` [ names ](/link/names?package=base&version=3.6.2)
(.) ` of ` target ` and ` current ` should be compared.

##  Value

Either ` TRUE ` ( ` NULL ` for ` attr.all.equal ` ) or a vector of ` [ mode
](/link/mode?package=base&version=3.6.2) ` ` "character" ` describing the
differences between ` target ` and ` current ` .

##  Details

` all.equal ` is a generic function, dispatching methods on the ` target `
argument. To see the available methods, use ` [ methods
](/link/methods?package=base&version=3.6.2) ("all.equal") ` , but note that
the default method also does some dispatching, e.g.using the raw method for
logical targets.

Remember that arguments which follow ` … ` must be specified by
(unabbreviated) name. It is inadvisable to pass unnamed arguments in ` … ` as
these will match different arguments in different methods.

Numerical comparisons for ` scale = NULL ` (the default) are typically on
_relative difference_ scale unless the target values are close t