compareEqual {compare} | R Documentation |
Compare two objects and allow for various minor differences between them.
compareEqual(model, comparison, transform = character(), ...) ## S3 method for class 'logical': compareEqual(model, comparison, transform = character(), ...) ## S3 method for class 'numeric': compareEqual(model, comparison, transform = character(), round=FALSE, ...) ## S3 method for class 'character': compareEqual(model, comparison, transform=character(), ignoreCase=FALSE, trim=FALSE, ...) ## S3 method for class 'factor': compareEqual(model, comparison, transform=character(), dropLevels=FALSE, ignoreLevelOrder=FALSE, ...) ## S3 method for class 'matrix': compareEqual(model, comparison, transform=character(), ignoreDimOrder=FALSE, ...) ## S3 method for class 'array': compareEqual(model, comparison, transform=character(), ignoreDimOrder=FALSE, ...) ## S3 method for class 'table': compareEqual(model, comparison, transform=character(), ignoreDimOrder=FALSE, ...) ## S3 method for class 'data.frame': compareEqual(model, comparison, transform=character(), ignoreColOrder=FALSE, ignoreNameCase=FALSE, ..., recurseFun=compareEqual) ## S3 method for class 'list': compareEqual(model, comparison, transform=character(), ignoreComponentOrder=FALSE, ignoreNameCase=FALSE, ..., recurseFun=compareEqual)
model |
The “correct” object. |
comparison |
The object to be compared with the model . |
transform |
A character vector containing any transformations that have been performed on the objects prior to this comparison. |
round |
For numeric vectors,
whether the objects should be rounded before comparison.
If FALSE there is no rounding, if TRUE both objects
are rounded to zero decimal places, if an integer value, then
both objects are rounded to the specified number of decimal
places. May also be a function (of one argument). |
ignoreCase |
For character vectors, whether to ignore the case of the strings. |
trim |
For character vectors, whether to ignore leading and trailing white space. |
dropLevels |
For factors, whether to drop unused levels before the comparison. |
ignoreLevelOrder |
For factors, whether to ignore the order of levels. |
ignoreDimOrder |
For matrices, arrays, and tables, whether to reorder of the dimensions by name before the comparison. |
ignoreColOrder |
For data frames, whether to reorder the columns by name before the comparison. |
ignoreComponentOrder |
For lists, whether to reorder the components by name before the comparison. |
ignoreNameCase |
For data frames and lists, whether to ignore the case of names when reordering components by name. |
... |
Other arguments controlling the comparison. |
recurseFun |
For data frames, the function to use to compare the columns of the data frames. For lists, the function used to compare the components of the list. |
This function compares two objects for identity (using
identical()
), then if that fails and equal=TRUE
,
compares the objects for equality. The arguments allow for
various relaxations on what “equal” means.
For numeric vectors, the comparison uses all.equal()
to allow for differences in floating-point representation.
The round
argument also allows for much more lenient
comparisons. The round
argument can also be a function,
e.g., floor()
(see other examples below).
An object of class "comparison"
.
Use isTRUE()
to determine whether the
comparison has succeeded.
Paul Murrell
compareEqual(letters, paste(" ", letters, " "), trim=TRUE) compareEqual(c(.1, 1, 10), c(.13, 1.3, 13), round=function(x) { signif(x, 1) })