-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUGZILLA #17897] all.equal(x,y) wrongly reports TRUE for factors containing different sorts of NAs #7068
Comments
NA METADATA
|
'y' can be produced by METADATA
|
NA METADATA
|
It looks like the current behavior may be intentional, based on the log of revision 56668, all.equal.factor predates character NAs METADATA
|
NA METADATA
|
Since the 2 factors act differently, e.g. in modelling functions, I think all.equal should report that they are not equivalent.
[1] TRUE
Call: Residuals: Coefficients: Residual standard error: 0.9129 on 3 degrees of freedom
Call: Residuals: Coefficients: Residual standard error: 0.7071 on 1 degrees of freedom METADATA
|
NA METADATA
|
NA METADATA
|
x <- structure(3:1, .Label = c("a", "b", NA), class = "factor")
y <- structure(c(NA, 2L, 1L), .Label = c("a", "b", NA), class = "factor")
all.equal(x, y)
# [1] TRUE
But is.na() gives different results for x and y.
all.equal(is.na(x), is.na(y))
#[1] "1 element mismatch"
is.na(x)
#[1] FALSE FALSE FALSE
is.na(y)
#[1] TRUE FALSE FALSE
I am not sure if ordinary R functions, aside from structure, would ever produce 'y', but the vroom package does and its tests use all.equal() to conclude inappropriately that x and y are equivalent. See tidyverse/vroom#262 for details.
METADATA
The text was updated successfully, but these errors were encountered: