tibble
tibble copied to clipboard
`[` can create non-unique names
tibble::tibble(x = 1)[rep(1, 3)]
#> # A tibble: 1 × 3
#> x x x
#> <dbl> <dbl> <dbl>
#> 1 1 1 1
Created on 2022-09-16 with reprex v2.0.2
This is documented in vignette("invariants"):
When subsetting repeated indexes, the resulting column names are undefined, do not rely on them.
Do we have reasons to change this behavior now?
It just seems unusual that we don't apply our standard name repair rules here.
I remember discussions around the invariant that names(x)[j] should be the same as names(x[j]) . We could run revdepchecks to see what the impact would be.?
I actually think this behavior is good and correct. I think [ is a suitably low level operation that it shouldn't apply automatic name repair because it is going to be used programmatically.
I know of at least 1 place where we use [ in a way that might generate names like this, but it works just fine anyways.
join_by(x >= lower, x <= upper) in dplyr will generate key data frames that have two columns where both columns are named x (because names come from the lhs input). These are essentially only used by vec_locate_matches() so the duplicate names don't hurt anything.
Agree to close?