compare {compare} | R Documentation |
Compare Two Objects
Description
Compare two objects and, if they are not the same, attempt to transform them to see if they are the same after being transformed.
Usage
compare(model, comparison,
equal = TRUE,
coerce = allowAll,
shorten = allowAll,
ignoreOrder = allowAll,
ignoreNameCase = allowAll,
ignoreNames = allowAll,
ignoreAttrs = allowAll,
round = FALSE,
ignoreCase = allowAll,
trim = allowAll,
dropLevels = allowAll,
ignoreLevelOrder = allowAll,
ignoreDimOrder = allowAll,
ignoreColOrder = allowAll,
ignoreComponentOrder = allowAll,
colsOnly = !allowAll,
allowAll = FALSE)
compareName(model, compName,
...,
ignore.case = TRUE,
compEnv = .GlobalEnv)
Arguments
model |
The “correct” object. |
comparison |
The object to be compared with the |
equal |
Test for equality if test for identity fails. |
coerce |
If objects are not the same, allow coercion of comparsion to model class. |
shorten |
If the length of one object is less than the other, shorten the longer object. |
ignoreOrder |
Ignore the order of values when comparing. |
ignoreNameCase |
Ignore the case of names when comparing. |
ignoreNames |
Ignore names attributes altogether. |
ignoreAttrs |
Ignore attributes altogether. |
round |
If objects are not the same, allow numbers to be rounded. |
ignoreCase |
Ignore the case of string values. |
trim |
Ignore leading and trailing spaces in string values. |
dropLevels |
If factors are not the same, allow unused levels to be dropped. |
ignoreLevelOrder |
Ignore the order of factor levels. |
ignoreDimOrder |
Ignore the order of dimensions when comparing matrices, arrays, or tables. |
ignoreColOrder |
Ignore the order of columns when comparing data frames. |
ignoreComponentOrder |
Ignore the order of components when comparing lists. |
colsOnly |
Only transform columns (not rows) when comparing data frames. |
allowAll |
Allow any sort of transformation (almost; see Details). |
compName |
A string giving the name of the comparison object. |
... |
Arguments to be passed to |
ignore.case |
Ignore the case of the name when searching for the comparison object. |
compEnv |
An environment within which to search for the comparison object. |
Details
The compare()
function compares two objects for equality.
The arguments
allow for various transformations of the objects (e.g., type
coercion) in order to try and achieve equality.
Specific transformations can be turned on via the appropriate
argument, or the allowAll
argument can be used to
enable all transformations, with the exception of
rounding of numeric values.
The compareName()
function is a wrapper for compare()
that requires the name of the comparison object rather than
the objects itself, plus it allows an environment to be supplied
that contains the actual comparison object. This is useful for the
situation where a particular object with a particular name should have
been generated and allows the generated object to differ from the
desired object in terms of the case of its name.
Value
An object of class "comparison"
.
This is a list. The most important components are result
,
which gives the overall success/failure of the comparison,
and transform
, which describes the transformations
attempted during the comparison (whether they were successful or not).
Author(s)
Paul Murrell
See Also
comparison-class
and
compareEqual
Examples
obj1 <- c("a", "a", "b", "c")
obj2 <- factor(obj1)
compare(obj1, obj2, allowAll=TRUE)