-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
dplyr 1.1.4 breaks on empty dataframes constructed from matrices #7004
Comments
I think this may actually be a base R bug. I believe that all data.frames should have a attributes(as.data.frame(matrix(nrow = 0, ncol = 0)))
#> $class
#> [1] "data.frame"
#>
#> $row.names
#> integer(0)
attributes(data.frame())
#> $names
#> character(0)
#>
#> $row.names
#> integer(0)
#>
#> $class
#> [1] "data.frame" Not having a # Good OOB error
df <- data.frame()
df[1]
#> Error in `[.data.frame`(df, 1): undefined columns selected
# WTF is this
df <- as.data.frame(matrix(nrow = 0, ncol = 0))
df[1]
#> NULL
#> <0 rows> (or 0-length row.names) In general dplyr works fine with the 2nd case, i.e. a well formed data frame I think we should consider switching from Line 14 in d698022
i.e. something like names <- names(data)
if (is.null(names)) {
abort("Can't transform a data frame with `NULL` names.")
} which would go nicely with our other names related checks there. It did use |
This has been fixed upstream in base R wch/r-source@ae3f49f For TDD, here is what I think we need to do to finish up the dplyr side. The changes take place here: Line 14 in d698022
We need to switch from
Both of these are typically "repaired" by rlang names <- names(data)
if (is.null(names)) {
abort("Can't transform a data frame with `NULL` names.")
}
if (vec_any_missing(names)) {
abort("Can't transform a data frame with missing names.")
}
names <- chr_unserialise_unicode(names) |
Previous versions of dplyr would allow you to manipulate empty dataframes that had been constructed from empty matrices, e.g.
In dplyr 1.1.4, this code causes an internal error:
Both versions are able to reliably manipulate empty dataframes that were not constructed from matrices (e.g.
data.frame() |> dplyr::slice(1)
works just fine).The text was updated successfully, but these errors were encountered: