-
Notifications
You must be signed in to change notification settings - Fork 66
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
vec_rbind() enforces row names when input is a named list #966
Comments
Both Would |
I understand the reason, but this spills over into I think a lot of people creates tibbles in an lapply call and binds them together. lapply might decide to name the elements and this will sometimes trigger a name repair |
CRAN dplyr didn't set row names using the input names, and only used them when I imagine we just need to tweak if (is_null(.id)) {
names(dots) <- NULL
} else {
if (!is_string(.id)) {
bad_args(".id", "must be a scalar string, ", "not {friendly_type_of(.id)} of length {length(.id)}")
}
if (!is_named(dots)) {
names(dots) <- seq_along(dots)
}
} |
If this is fixed in dplyr instead I’m good with it. I opened here at the request of Hadley |
Maybe we could support a sentinel for easily zapping the names, that
|
Alternatively, maybe this behaviour could occur only if the data frame already had row names? This is a case where I worry that applying the vector naming rules to row names might lead us down a painful path. |
I think this would be confusing, I'd prefer disabling the rows-naming altogether. Applying this behaviour in an existing function like |
Why aren't these the same case? vctrs::vec_c(a = c(1, 2, 3))
#> Error: Can't merge the outer name `a` with a vector of length > 1.
#> Please supply a `.name_spec` specification.
vctrs::vec_rbind(a = data.frame(1:3))
#> X1.3
#> a1 1
#> a2 2
#> a3 3 Created on 2020-03-30 by the reprex package (v0.3.0) |
It's a good idea to make these consistent. This wouldn't help with Thomas' example with 1-row data frames though. |
For @thomasp85's original problem, just improving the name repair would help: library(vctrs)
vec_rbind(
`1` = data.frame(x = 1:11),
`11` = data.frame(x = 1)
)
#> New names:
#> * `11` -> `11...1`
#> * `11` -> `11...12`
#> x
#> 11...1 1
#> 12 2
#> 13 3
#> 14 4
#> 15 5
#> 16 6
#> 17 7
#> 18 8
#> 19 9
#> 110 10
#> 111 11
#> 11...12 1 Created on 2020-03-30 by the reprex package (v0.3.0) But I really do think it should be harder to opt into row names |
Making the sentinel |
For consistency with `vec_c()`. Closes r-lib#966.
For consistency with `vec_c()`. Closes r-lib#966.
For consistency with `vec_c()`. Closes #966.
When passing in a named list of data frames without row names to
vec_rbind()
the return value is a data frame with row names. This change can potentially trigger a hard-to-debug renaming message, e.g.The text was updated successfully, but these errors were encountered: