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 |
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: