Skip to content
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

.name_repair in as_tibble() doesn't check the name for rownames coerced to a column #1070

Closed
smped opened this issue Mar 11, 2022 · 3 comments · Fixed by #1512
Closed

.name_repair in as_tibble() doesn't check the name for rownames coerced to a column #1070

smped opened this issue Mar 11, 2022 · 3 comments · Fixed by #1512

Comments

@smped
Copy link

smped commented Mar 11, 2022

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"
@krlmlr
Copy link
Member

krlmlr commented Mar 16, 2022

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)

@smped
Copy link
Author

smped commented Mar 22, 2022

Yeah. That works nicely! Thanks for the follow up.

@krlmlr krlmlr added the bug an unexpected problem or unintended behavior label Mar 23, 2022
@krlmlr krlmlr added documentation and removed bug an unexpected problem or unintended behavior labels Apr 26, 2022
@krlmlr
Copy link
Member

krlmlr commented Apr 26, 2022

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.

@krlmlr krlmlr closed this as completed in 78f8fc6 Feb 23, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Feb 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants