all.equal(target, current)

Check if two objects are equal, or at least very nearly equal. Don’t get tripped up by the argument names, which make it sound like this function is only for a very specific scenario (convergence) when in truth it can be used for a wide variety of scenarios.

- target – An R object.
- current – A second R object to compare to target (the first argument).

As noted in the complete help file, if using all.equal in an if statement, wrap it inside of the isTRUE function.

Example. I look at several approximations of π and, eventually, all.equal will be satisfied that the values are sufficiently close to each other.

> > all.equal(pi, 3.14) [1] "Mean relative difference: 0.0005069574" > > all.equal(pi, 3.1415) [1] "Mean relative difference: 2.949255e-05" > > all.equal(pi, 3.1415 * (1 + 2.949255e-5)) [1] TRUE > > all.equal(pi, 3.141592) [1] "Mean relative difference: 2.080441e-07" > > all.equal(pi, 3.14159265) [1] TRUE >