Optionally ignore indices in all.equal

Open
#6,134 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
38/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
r
Domain
data

Research direction

Start at the all.equal.data.table entry point and trace how differences in data.table indices are detected and reported. Check how the existing check.attributes option is handled, then add a narrowly scoped option for ignoring indices and verify that column-name differences remain detectable.

Written by the indexing model from the issue text.

Description

feature request

Different tables that contain the same data and also behave pretty much the same will not be all.equal() when they have different indices. Indices can sometimes appear automatically depending on what operations are performed with tables, so I think it can often be reasonable to ignore differences in indices.

x <- data.table(a = 1)
y <- data.table(a = 1)
all.equal(x, y)
#> [1] TRUE
x[a == 1]
#>        a
#>    <num>
#> 1:     1
all.equal(x, y)  # would be nice to have a way to get 'TRUE' here
#> [1] "Datasets have different indices. 'target': [a]. 'current': has no index."

While one can set check.attributes = FALSE, this also ignores other more important things like column names

all.equal(x, y, check.attributes = FALSE)
#> [1] TRUE
all.equal(x, data.table(b = 1), check.attributes = FALSE)  # this is too lenient
#> [1] TRUE

The user can set / unset indices in tables before checking with all.equals(), but that gets unnecessarily complicated when the tables are buried inside larger objects.

It would therefore be useful to have an option check.indices or ignore.indices that makes all.equal() ignore data.table indices.

My use case is that I use all.equal.data.table a lot in unit tests, where I verify that objects created in different ways still contain the same data. Tables may have different indices depending on how objects are created, but because these indices make no relevant difference in object behaviour I would like to ignore them.

Dominant language
R
Stars
3.9k
Forks
1.1k
Avg merge
14h 4m
Merged PRs (30d)
4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Rdatatable/data.table

All issues in Rdatatable/data.table

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.