Test Two Numeric Objects for Full Equality

DESCRIPTION:

Returns TRUE or a message about what is different between the two objects.

This function is called for numeric data by the default method for the S Version 3 generic all.equal.

USAGE:

all.equal.numeric(target, current, tolerance=, scale,  ...) 

REQUIRED ARGUMENTS:

target, current
two objects that are asserted to be the result of equivalent computations (for example, the same computation on two different computers, or a revised but still correct version of the same computation). By convention, the first argument is the supposedly correct version, typically from an object stored after earlier computation. The second argument is the result of a computation just completed, whose correctness is to be tested.

OPTIONAL ARGUMENTS:

tolerance
tolerance to be used to compare numeric components. Default is the square root of the machine precision for double precision computations, i.e., sqrt(.Machine$double.eps). The test used is on absolute difference if the target value is less than or equal to the tolerance, and on relative difference otherwise, measured in mean absolute values (not mean square).
scale
a numeric value specifying the desired scaling of the mean absolute difference. For scale=1, you get the equivalent of absolute scaling, although the output will read "Mean scaled difference:".

VALUE:

If all components and attributes of the two objects test equal, returns TRUE . Otherwise, returns a character vector giving all the discovered differences.

DETAILS:

The all.equal methods are fussy tests that will generally report any differences even those that might sometimes be considered irrelevant. For example, using dump on a function, then restore may result in an equivalent function with comments parsed differently (and which prints with different white space). The only substantial leniency in the default methods is that numerical equality is tested only up to tolerance. Additional leniency can be built in by writing methods for special classes of objects.

SEE ALSO:

, .

EXAMPLES:

new.fit <- update(old.fit) 
all.equal(new.fit,old.fit) 

#Use scale parameter to obtain absolute difference
set.seed(17)
x <- matrix(1000*rnorm(12), ncol=3)
y <- x
y[4,3] <- 578.82
all.equal(x,y, tol=1e-5)
all.equal(x,y, tol=1e-5, scale=1)