\Header{all.equal}{Test if Two Objects are (Nearly) Equal}
\methalias{all.equal.character}{all.equal}
\methalias{all.equal.default}{all.equal}
\methalias{all.equal.factor}{all.equal}
\methalias{all.equal.formula}{all.equal}
\methalias{all.equal.language}{all.equal}
\methalias{all.equal.list}{all.equal}
\methalias{all.equal.numeric}{all.equal}
\alias{attr.all.equal}{all.equal}
\keyword{utilities}{all.equal}
\keyword{logic}{all.equal}
\keyword{arith}{all.equal}
\begin{Description}\relax
\code{all.equal(x,y)} is a utility to compare \R{} objects \code{x}
and \code{y} testing ``near equality''.  If they are different,
comparison is still made to some extent, and a report of the
differences is returned.  Don't use \code{all.equal} directly in
\code{if} expressions---either use \code{\Link{identical}} or combine
the two, as shown in the documentation for \code{identical}.\end{Description}
\begin{Usage}
\begin{verbatim}
all.equal(target, current, ...)

all.equal.numeric(target, current,
                  tolerance= .Machine$double.eps ^ 0.5, scale=NULL, ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{target}] \R{} object.
\item[\code{current}] other \R{} object, to be compared with \code{target}.
\item[\code{...}] Further arguments for different methods, notably the
following two, for numerical comparison:
\item[\code{tolerance}] numeric \eqn{\ge}{>=} 0.  Differences smaller than
\code{tolerance} are not considered.
\item[\code{scale}] numeric scalar > 0 (or \code{NULL}). See Details.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
There are several methods available, most of which are dispatched by
the default method, see \code{\Link{methods}("all.equal")}.
\code{all.equal.list} and \code{all.equal.language} provide
comparison of recursive objects.

Numerical comparisons for \code{scale = NULL} (the default) are done
by first computing the mean absolute difference of the two numerical
vectors. If this is smaller than \code{tolerance} or not finite,
absolute differences are used, otherwise relative differences scaled
by the mean absolute difference.

If \code{scale} is positive, comparisons are after scaling by \code{scale}.

For complex arguments, \code{\Link{Mod}} of difference is used.

\code{attr.all.equal} is used for comparing
\code{\Link{attributes}}, returning \code{NULL} or \code{character}.\end{Details}
\begin{Value}
Either \code{TRUE} or a vector of \code{\Link{mode}}
\code{"character"} describing the differences between \code{target}
and \code{current}.

Numerical differences are reported by relative error\end{Value}
\begin{SeeAlso}\relax
\code{\Link{==}}, and \code{\Link{all}} for exact equality testing.\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
all.equal(pi, 355/113) # not precise enough (default tol) > relative error

stopifnot(
all.equal(gamma(2:14),   cumprod(1:13))) # TRUE, but

all      (gamma(2:14) == cumprod(1:13)) # FALSE, since not exactly
all.equal(gamma(2:14),   cumprod(1:13), tol=0) # to see difference

all.equal(options(), .Options)
all.equal(options(), as.list(.Options))# TRUE
.Options $ myopt <- TRUE
all.equal(options(), as.list(.Options))
rm(.Options)
\end{ExampleCode}
\end{Examples}

