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

Clarity of "duplicated" error message in rename_with() #7006

Open
DanChaltiel opened this issue Mar 28, 2024 · 0 comments
Open

Clarity of "duplicated" error message in rename_with() #7006

DanChaltiel opened this issue Mar 28, 2024 · 0 comments

Comments

@DanChaltiel
Copy link
Contributor

Hi,

When using rename_with() and ending with duplicated column names, the error message tells us about the transformed, duplicated name and the location of the original columns.

However, it would be much clearer to have the original column names in the error message.

The locations are not of much help if rename_with() is used in a long pipeline, nor is the transformed name if the function is not well described.

Here is an example case:

library(tidyverse)
letter_sum = function(x){
  x %>% map_chr(~{str_split_1(.x, "") %>% map_int(~which(letters==tolower(.x))) %>% sum() %>% as.character()})
}
mtcars %>% rename_with(letter_sum)
#> Error in `rename_with()`:
#> ! Names must be unique.
#> x These names are duplicated:
#>   * "24" at locations 4 and 11.
#>   * "43" at locations 5 and 6.

Created on 2024-03-28 with reprex v2.1.0

While I admit the transformation is exaggeratedly nonsensical, it shows that the error is not very useful in such cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant