-
-
Notifications
You must be signed in to change notification settings - Fork 47
Description
Hi shinystan team,
We noticed that gtools is orphaned https://cran.r-project.org/web/packages/gtools/index.html, we were wondering if you'd consider replacing your usage of it with something else.
It seems that you use gtools::mixedsort()
to ensure that sorting is done correctly with respect to numeric character strings.
shinystan/inst/ShinyStan/server_files/utilities/make_param_list_with_groups_sort.R
Lines 26 to 28 in e35c817
# change sorting so e.g. "beta[1,1] beta[1,2] beta[2,1] beta[2,2]" | |
# instead of "beta[1,1] beta[2,1] beta[1,2] beta[2,2]" | |
ch <- gtools::mixedsort(ch) |
I'm not sure the comment there is correct, because sort()
works as you expect on that specific example. However, it does matter when you sort strings like c("1", "2", "10")
because the 10 will come before the 2 with typical sort methods. You could use stringi instead of gtools for this purpose if you are looking for a good replacement:
# Small numbers aren't a problem with base sort()
x <- c("beta[1,1]", "beta[1,2]", "beta[2,1]", "beta[2,2]")
sort(x)
#> [1] "beta[1,1]" "beta[1,2]" "beta[2,1]" "beta[2,2]"
gtools::mixedsort(x)
#> [1] "beta[1,1]" "beta[1,2]" "beta[2,1]" "beta[2,2]"
# Maybe it was for this?
x <- c("beta[1,1]", "beta[2,1]", "beta[10,1]")
sort(x)
#> [1] "beta[1,1]" "beta[10,1]" "beta[2,1]"
gtools::mixedsort(x)
#> [1] "beta[1,1]" "beta[2,1]" "beta[10,1]"
# You can sort that "correctly" with stringi instead
stringi::stri_sort(x, numeric = TRUE)
#> [1] "beta[1,1]" "beta[2,1]" "beta[10,1]"
Created on 2022-06-16 by the reprex package (v2.0.1)