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

arrange not working with integer64 + another column #6268

Closed
jameelalsalam opened this issue May 12, 2022 · 1 comment · Fixed by #6296
Closed

arrange not working with integer64 + another column #6268

jameelalsalam opened this issue May 12, 2022 · 1 comment · Fixed by #6296
Labels
bug an unexpected problem or unintended behavior

Comments

@jameelalsalam
Copy link

It appears that using arrange with an integer64 column and another column does not re-order the second column as expected. I think I can work around this with group_by + arrange, but seemed worth a report.

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

tibble(
  id = bit64::as.integer64(1),
  year = c(1, 3, 2)
) %>%
  arrange(id, year)
#> # A tibble: 3 x 2
#>        id  year
#>   <int64> <dbl>
#> 1       1     1
#> 2       1     3
#> 3       1     2

Created on 2022-05-12 by the reprex package (v2.0.1)

Session info
sessioninfo::session_info()
#> - Session info ---------------------------------------------------------------
#>  setting  value
#>  version  R version 4.1.3 (2022-03-10)
#>  os       Windows 10 x64 (build 19042)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language (EN)
#>  collate  English_United States.1252
#>  ctype    English_United States.1252
#>  tz       America/New_York
#>  date     2022-05-12
#>  pandoc   2.17.1.1 @ C:/Program Files/RStudio/bin/quarto/bin/ (via rmarkdown)
#> 
#> - Packages -------------------------------------------------------------------
#>  ! package     * version date (UTC) lib source
#>  P assertthat    0.2.1   2019-03-21 [?] CRAN (R 4.1.1)
#>  P bit           4.0.4   2020-08-04 [?] CRAN (R 4.1.1)
#>  P bit64         4.0.5   2020-08-30 [?] CRAN (R 4.1.1)
#>  P cli           3.2.0   2022-02-14 [?] CRAN (R 4.1.3)
#>  P crayon        1.5.1   2022-03-26 [?] CRAN (R 4.1.3)
#>  P DBI           1.1.2   2021-12-20 [?] CRAN (R 4.1.3)
#>  P digest        0.6.29  2021-12-01 [?] CRAN (R 4.1.3)
#>  P dplyr       * 1.0.9   2022-04-28 [?] CRAN (R 4.1.3)
#>  P ellipsis      0.3.2   2021-04-29 [?] CRAN (R 4.1.1)
#>  P evaluate      0.15    2022-02-18 [?] CRAN (R 4.1.3)
#>  P fansi         1.0.3   2022-03-24 [?] CRAN (R 4.1.3)
#>  P fastmap       1.1.0   2021-01-25 [?] CRAN (R 4.1.1)
#>  P fs            1.5.2   2021-12-08 [?] CRAN (R 4.1.3)
#>  P generics      0.1.2   2022-01-31 [?] CRAN (R 4.1.3)
#>  P glue          1.6.2   2022-02-24 [?] CRAN (R 4.1.3)
#>  P highr         0.9     2021-04-16 [?] CRAN (R 4.1.1)
#>  P htmltools     0.5.2   2021-08-25 [?] CRAN (R 4.1.1)
#>  P knitr         1.38    2022-03-25 [?] CRAN (R 4.1.3)
#>  P lifecycle     1.0.1   2021-09-24 [?] CRAN (R 4.1.1)
#>  P magrittr      2.0.3   2022-03-30 [?] CRAN (R 4.1.3)
#>  P pillar        1.7.0   2022-02-01 [?] CRAN (R 4.1.3)
#>  P pkgconfig     2.0.3   2019-09-22 [?] CRAN (R 4.1.1)
#>  P purrr         0.3.4   2020-04-17 [?] CRAN (R 4.1.1)
#>  P R6            2.5.1   2021-08-19 [?] CRAN (R 4.1.1)
#>  P reprex        2.0.1   2021-08-05 [?] CRAN (R 4.1.1)
#>  P rlang         1.0.2   2022-03-04 [?] CRAN (R 4.1.3)
#>  P rmarkdown     2.13    2022-03-10 [?] CRAN (R 4.1.3)
#>  P rstudioapi    0.13    2020-11-12 [?] CRAN (R 4.1.1)
#>  P sessioninfo   1.2.2   2021-12-06 [?] CRAN (R 4.1.3)
#>  P stringi       1.7.6   2021-11-29 [?] CRAN (R 4.1.2)
#>  P stringr       1.4.0   2019-02-10 [?] CRAN (R 4.1.1)
#>  P tibble        3.1.6   2021-11-07 [?] CRAN (R 4.1.3)
#>  P tidyselect    1.1.2   2022-02-21 [?] CRAN (R 4.1.3)
#>  P utf8          1.2.2   2021-07-24 [?] CRAN (R 4.1.1)
#>  P vctrs         0.4.1   2022-04-13 [?] CRAN (R 4.1.3)
#>  P withr         2.5.0   2022-03-03 [?] CRAN (R 4.1.3)
#>  P xfun          0.30    2022-03-02 [?] CRAN (R 4.1.3)
#>  P yaml          2.3.5   2022-02-21 [?] CRAN (R 4.1.2)
#> 
#>  [1] C:/Users/jalsal02/R/renv/library/ONGwells-7ad48f06/R-4.1/x86_64-w64-mingw32
#>  [2] C:/Program Files/R/R-4.1.3/library
#> 
#>  P -- Loaded and on-disk path mismatch.
#> 
#> ------------------------------------------------------------------------------
@DavisVaughan
Copy link
Member

Yea, this isn't quite right

dplyr/R/arrange.R

Lines 156 to 158 in dbda0c7

proxy <- order(vec_order(proxy,
direction = direction,
na_value = if(desc) "smallest" else "largest"

You lose the fact that the 3 1s are identical. i.e. it basically does this

# Lose that fact that the 3 `1`s are identical
x <- bit64::as.integer64(c(1, 1, 1))
order(vctrs::vec_order(x))
#> [1] 1 2 3

So then it thinks the first column is already sorted and doesn't look to the second one to break ties.

Luckily this will be fixed by #6263 because it removes the hack we had to do there

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants