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

distinct() doesn't respect user-specified column order #6156

Closed
sfirke opened this issue Jan 14, 2022 · 4 comments · Fixed by #6346
Closed

distinct() doesn't respect user-specified column order #6156

sfirke opened this issue Jan 14, 2022 · 4 comments · Fixed by #6346
Labels
bug an unexpected problem or unintended behavior rows ↕️ Operations on rows: filter(), slice(), arrange()

Comments

@sfirke
Copy link
Contributor

sfirke commented Jan 14, 2022

I'm again experiencing behavior that was reported as #3195, then closed years ago. I'll use the same reprex. Running dplyr 1.0.7.

starwars %>% distinct(skin_color, hair_color)

#> # A tibble: 50 x 2
#>    hair_color    skin_color 
#>    <chr>         <chr>      
#>  1 blond         fair       
#>  2 <NA>          gold       
#>  3 <NA>          white, blue
#>  4 none          white      
#>  5 brown         light      
#>  6 brown, grey   light      
#>  7 <NA>          white, red 
#>  8 black         light      
#>  9 auburn, white fair       
#> 10 auburn, grey  fair       
#> # ... with 40 more rows
Created on 2022-01-14 by the reprex package (v2.0.1)
@hadley
Copy link
Member

hadley commented Apr 16, 2022

Actual reprex:

library(dplyr, warn.conflicts = FALSE)
starwars %>% distinct(skin_color, hair_color)
#> # A tibble: 50 × 2
#>    hair_color    skin_color 
#>    <chr>         <chr>      
#>  1 blond         fair       
#>  2 <NA>          gold       
#>  3 <NA>          white, blue
#>  4 none          white      
#>  5 brown         light      
#>  6 brown, grey   light      
#>  7 <NA>          white, red 
#>  8 black         light      
#>  9 auburn, white fair       
#> 10 auburn, grey  fair       
#> # … with 40 more rows

Created on 2022-04-16 by the reprex package (v2.0.1)

@hadley hadley added bug an unexpected problem or unintended behavior rows ↕️ Operations on rows: filter(), slice(), arrange() labels Apr 16, 2022
@hadley
Copy link
Member

hadley commented Jul 21, 2022

Looks like I broke this by accident in #4691

@machow
Copy link

machow commented Oct 6, 2022

It seems like this may have resurfaced (reprex using v1.0.10):

library(dplyr, warn.conflicts = FALSE)

head(mtcars, 2)
#>               mpg cyl disp  hp drat    wt  qsec vs am gear carb
#> Mazda RX4      21   6  160 110  3.9 2.620 16.46  0  1    4    4
#> Mazda RX4 Wag  21   6  160 110  3.9 2.875 17.02  0  1    4    4

distinct(mtcars, cyl, mpg) %>% head(2)
#>             mpg cyl
#> Mazda RX4  21.0   6
#> Datsun 710 22.8   4

Created on 2022-10-06 by the reprex package (v2.0.1)

@DavisVaughan
Copy link
Member

Fixed in the dev version though!

library(dplyr, warn.conflicts = FALSE)

distinct(mtcars, cyl, mpg) %>% head(2)
#>            cyl  mpg
#> Mazda RX4    6 21.0
#> Datsun 710   4 22.8

Created on 2022-10-06 with reprex v2.0.2.9000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior rows ↕️ Operations on rows: filter(), slice(), arrange()
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants