compareEqual: Compare Two Objects for Equality

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/same.R

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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) 

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.

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

Value

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

Author(s)

Paul Murrell

See Also

compare

Examples

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

compare documentation built on May 2, 2019, 10:24 a.m.