tibble
tibble copied to clipboard
.name_repair in `as_tibble()` doesn't check the name for rownames coerced to a column
When providing an obviously dumb name for a new column containing rownames, .name_repair doesn't appear to check the name of the new column against existing columns
as_tibble(data.frame(a = 1:5), rownames = "a", .name_repair = "unique")
# A tibble: 5 × 2
a a
<chr> <int>
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
To my understanding, this should spit the following message and output as the names
vctrs::vec_as_names(c("a", "a"), repair = "unique")
New names:
* a -> a...1
* a -> a...2
[1] "a...1" "a...2"
Thanks, good catch. For code that works before and after we fix that, would as_tibble(rownames_to_column(...))
work?
tibble::rownames_to_column(data.frame(a = 1:3), var = "a")
#> Error:
#> ! Column name `a` must not be duplicated.
#> Caused by error in `stop_vctrs()`:
#> ! Names must be unique.
#> x These names are duplicated:
#> * "a" at locations 1 and 2.
Created on 2022-03-16 by the reprex package (v2.0.1)
Yeah. That works nicely! Thanks for the follow up.
Let's leave it "as is", because name repair can e.g. also be a function that returns a value independent of its input, as seen in the inspectdf package. It's easy to work around anyway.
Happy to document this glitch.