You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently all.equal.data.table gives a hard error when the second argument is not a data.table:
library(data.table)
df<-data.frame(a=1)
dt<- as.data.table(df)
all.equal(df, dt)
#> [1] "Attributes: < Names: 1 string mismatch >" #> [2] "Attributes: < Length mismatch: comparison on first 2 components >" #> [3] "Attributes: < Component \"class\": Lengths (1, 2) differ (string compare on first 1) >"#> [4] "Attributes: < Component \"class\": 1 string mismatch >" #> [5] "Attributes: < Component 2: Modes: numeric, externalptr >" #> [6] "Attributes: < Component 2: target is numeric, current is externalptr >"
all.equal(dt, df)
#> Error in all.equal.data.table(dt, df): 'target' and 'current' must both be data.tables
(the error is also thrown if the first argument is not a data.table, but that would only happen if you bypassed method dispatch, in which case it's your own fault)
This makes it impossible to use common paradigms such as if (isTRUE(all.equal(x, y)) {...} : I would have to throw a try in there just to handle the case that x (or one of its list elements or attributes) is a data.table and y (or its corresponding element/attribute) isn't. More generally, it seems bad that all.equal(x, y) could have such substantially different behaviour than all.equal(y, x).
This error is thrown near the very top of all.equal.data.table:
if (!is.data.table(target) ||!is.data.table(current))
stop("'target' and 'current' must both be data.tables")
I see two possible and very simple remedies:
Literally just replace stop with return (possibly tailoring the message to tell you which one isn't a data.table)
Replace the whole stop clause with NextMethod() or explicit all.equal.default (such that all.equal(dt, df) would give approximately the same message as all.equal(df, dt).
Tests 1613.59 and 1613.60 explicitly check for this error, so maybe this is intentional, but consider this my request to change that. If I get a approval on either remedy, I could do the PR myself (it would be my first for an open source project, but seems simple enough!)
Currently
all.equal.data.table
gives a hard error when the second argument is not a data.table:(the error is also thrown if the first argument is not a data.table, but that would only happen if you bypassed method dispatch, in which case it's your own fault)
This makes it impossible to use common paradigms such as
if (isTRUE(all.equal(x, y)) {...}
: I would have to throw atry
in there just to handle the case thatx
(or one of its list elements or attributes) is a data.table andy
(or its corresponding element/attribute) isn't. More generally, it seems bad thatall.equal(x, y)
could have such substantially different behaviour thanall.equal(y, x)
.This error is thrown near the very top of
all.equal.data.table
:I see two possible and very simple remedies:
stop
withreturn
(possibly tailoring the message to tell you which one isn't a data.table)stop
clause withNextMethod()
or explicitall.equal.default
(such thatall.equal(dt, df)
would give approximately the same message asall.equal(df, dt)
.Tests 1613.59 and 1613.60 explicitly check for this error, so maybe this is intentional, but consider this my request to change that. If I get a approval on either remedy, I could do the PR myself (it would be my first for an open source project, but seems simple enough!)
The text was updated successfully, but these errors were encountered: