Learn R Programming

compare (version 0.2-6)

compareEqual: Compare Two Objects for Equality

Description

Compare two objects and allow for various minor differences between them.

Usage

compareEqual(model, comparison, transform = character(), ...)
"compareEqual"(model, comparison, transform = character(), ...)
"compareEqual"(model, comparison, transform = character(), round=FALSE, ...)
"compareEqual"(model, comparison, transform=character(), ignoreCase=FALSE, trim=FALSE, ...)
"compareEqual"(model, comparison, transform=character(), dropLevels=FALSE, ignoreLevelOrder=FALSE, ...)
"compareEqual"(model, comparison, transform=character(), ignoreDimOrder=FALSE, ...)
"compareEqual"(model, comparison, transform=character(), ignoreDimOrder=FALSE, ...)
"compareEqual"(model, comparison, transform=character(), ignoreDimOrder=FALSE, ...)
"compareEqual"(model, comparison, transform=character(), ignoreColOrder=FALSE, ignoreNameCase=FALSE, ..., recurseFun=compareEqual)
"compareEqual"(model, comparison, transform=character(), ignoreComponentOrder=FALSE, ignoreNameCase=FALSE, ..., recurseFun=compareEqual)

Arguments

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.

Value

An object of class "comparison". Use isTRUE() to determine whether the comparison has succeeded.

Details

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).

See Also

compare

Examples

Run this code
compareEqual(letters, paste(" ", letters, " "), trim=TRUE)
compareEqual(c(.1, 1, 10), c(.13, 1.3, 13),
             round=function(x) { signif(x, 1) })

Run the code above in your browser using DataLab