all.equal
Test Two Objects for Full Equality

Description

Tests the two specified functions for differences.
This function is an S Version 3 generic (see Methods). You can write method functions to handle specific S Version 3 classes of data. Classes that have methods for this function include numeric, factor, and the default method.

Usage

all.equal(target, current, ...)
## S3 method for class 'POSIXct':
all.equal(target, current, ..., scale = 1)

Arguments

target, current two objects asserted to be the result of equivalent computations. For example, these can be 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 considered the correct version, usually from an object stored after earlier computation. The second argument is the result of a computation just completed, whose correctness is to be tested.
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:".
... other arguments you can apply to the method functions. See Details.

Details

The all.equal methods usually report differences--even those that you might consider irrelevant. The only substantial leniency in the default methods is that numerical equality is tested only up to tolerance. You can build in additional leniency by writing methods for special classes of objects.
Value
returns TRUE if all components and attributes of the two objects are equal; otherwise, it returns a character vector containing all discovered differences.
The all.equal.POSIXct() either returns the mean difference of the given dates with specified scale or a logical value TRUE if both target and current are equal.
See Also
Comparison, POSIXt
Examples
all.equal(c(1,2,3), c(1,2,3))
# [1] TRUE

all.equal(c(1,2,3), c(1,2+1e-5,3)) # [1] "Mean relative difference: 5e-006"

all.equal(c(1,2,3), c(1,2+1e-5,3), tolerance=1e-4) # [1] TRUE

all.equal(structure(1:3, foo=1), structure(1:3, foo=2)) # [1] "Attributes: < Component foo: Mean relative difference: 1 >"

all.equal(structure(1:3, foo=1), structure(1:3, foo=2), check.attributes=FALSE) # [1] TRUE

## POSIXct x <- as.POSIXct("1970-01-01 00:00:00") all.equal(x, x - 3, scale = 5)

y <- x attr(y, "tzone") <- "Asia/Shanghai" all.equal(x, y)

z <- x attr(z, "tzone") <- "America/New_York" all.equal(y, z)

Package base version 6.0.0-69
Package Index