Here we offer end-to-end examples of using dataCompareR and, for those who want to know, to provide details of how the package performs the comparison.
For the purpose of this vignette we’ll intentionally modify iris to use for our comparison.
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1 5.1 3.5 1.4 0.2 setosa
## 2 4.9 3.0 1.4 0.2 setosa
## 3 4.7 3.2 1.3 0.2 setosa
## 4 4.6 3.1 1.5 0.2 setosa
## 5 5.0 3.6 1.4 0.2 setosa
## 6 5.4 3.9 1.7 0.4 setosa
# Make a copy of iris
iris2 <- iris
# And change it, first by subsetting just the first 140 rows
iris2 <- iris2[1:140,]
# then removing the Petal.Width column
iris2$Petal.Width <- NULL
# And then changing some values
iris2[1:10,1] <- iris2[1:10,1] + 1
And then run a comparison using the rCompare
function
## Running rCompare...
## Warning: `select_()` was deprecated in dplyr 0.7.0.
## ℹ Please use `select()` instead.
## ℹ The deprecated feature was likely used in the dataCompareR package.
## Please report the issue at
## <https://github.com/capitalone/dataCompareR/issues>.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
rCompare
returns an S3 object which you can use with
summary and print. Summary is a good way to check the results
## dataCompareR is generating the summary...
##
## Data Comparison
## ===============
##
## Date comparison run: 2025-03-12 04:59:44.426165
## Comparison run on R version 4.4.3 (2025-02-28)
## With dataCompareR version 0.1.4
##
##
## Meta Summary
## ============
##
##
## |Dataset Name |Number of Rows |Number of Columns |
## |:------------|:--------------|:-----------------|
## |iris |150 |5 |
## |iris2 |140 |4 |
##
##
## Variable Summary
## ================
##
## Number of columns in common: 4
## Number of columns only in iris: 1
## Number of columns only in iris2: 0
## Number of columns with a type mismatch: 0
## No match key used, comparison is by row
##
##
## Columns only in iris: PETAL.WIDTH
## Columns in both : PETAL.LENGTH, SEPAL.LENGTH, SEPAL.WIDTH, SPECIES
##
## Row Summary
## ===========
##
## Total number of rows read from iris: 150
## Total number of rows read from iris2: 140
## Number of rows in common: 140
## Number of rows dropped from iris: 10
## Number of rows dropped from iris2: 0
##
##
## Data Values Comparison Summary
## ==============================
##
## Number of columns compared with ALL rows equal: 3
## Number of columns compared with SOME rows unequal: 1
## Number of columns with missing value differences: 0
##
## Columns with all rows equal : PETAL.LENGTH, SEPAL.WIDTH, SPECIES
##
## Summary of columns with some rows unequal:
##
##
##
## |Column |Type (in iris) |Type (in iris2) | # differences|Max difference | # NAs|
## |:------------|:--------------|:---------------|-------------:|:--------------|-----:|
## |SEPAL.LENGTH |double |double | 10|1 | 0|
##
##
##
## Unequal column details
## ======================
##
##
##
## #### Column - SEPAL.LENGTH
## Showing sample of size 5
##
##
##
## | | SEPAL.LENGTH (iris)| SEPAL.LENGTH (iris2)|Type (iris) |Type (iris2) | Difference|
## |:--|-------------------:|--------------------:|:-----------|:------------|----------:|
## |1 | 4.7| 5.7|double |double | -1|
## |2 | 4.6| 5.6|double |double | -1|
## |3 | 4.6| 5.6|double |double | -1|
## |4 | 5.1| 6.1|double |double | -1|
## |5 | 4.9| 5.9|double |double | -1|
Or you save a copy of the report using saveReport
In the first example, we compared our data based on it’s order. What if want to match our data of a key? We’ll produce another test data set based on the pressure dataset
## temperature pressure
## 1 0 0.0002
## 2 20 0.0012
## 3 40 0.0060
## 4 60 0.0300
## 5 80 0.0900
## 6 100 0.2700
# Make a copy of pressure
pressure2 <- pressure
# And change it, first by randomising the row order
pressure2 <- pressure2[sample(nrow(pressure2)),]
# then changing just one element, so for temperature of
pressure2[5,1]
## [1] 320
Run the comparison with rCompare
specifying that we want
to match on temperature
## Running rCompare...
## Warning: `arrange_()` was deprecated in dplyr 0.7.0.
## ℹ Please use `arrange()` instead.
## ℹ See vignette('programming') for more help
## ℹ The deprecated feature was likely used in the dataCompareR package.
## Please report the issue at
## <https://github.com/capitalone/dataCompareR/issues>.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
And this time, we’ll choose to get a shorter summary using
print
## All columns were compared, all rows were compared
## There are 1 mismatched variables:
## First and last 5 observations for the 1 mismatched variables
## TEMPERATURE valueA valueB variable typeA typeB diffAB
## 1 320 376 752 PRESSURE double double -376
We can also extract the mismatching data to explore further using
generateMismatchData
which generates a list containing two
data frames, each having the missing rows from the comparison.
# use generateMismatchData to pull out the mismatching rows from each table
mismatches <- generateMismatchData(compPressure, pressure, pressure2)
mismatches
## $pressure_mm
## TEMPERATURE PRESSURE
## 1 320 376
##
## $pressure2_mm
## TEMPERATURE PRESSURE
## 1 320 752
It is possible to use the other functions not exposed to the end user
through the 3 colons format like
dataCompareR:::functionName
. Please take care when using
them, as some of the checks are done up front, so they may make
assumptions on the input.
The aspects of the dataCompareR::rCompare function that matter to the end user are:-
as.data.frame
. If you need more advanced
coercion, please do this before calling dataCompareR.NA
and NaN
, which are handled
in the following way
NA
, match is
TRUE
NaN
, match is
TRUE
NA
and the other NaN
,
match is FALSE
NA
, and the other is a valid value,
match is FALSE
NaN
, and the other is a valid value,
match is FALSE