Skip to content

gtools is orphaned - Consider a replacement? #196

@DavisVaughan

Description

@DavisVaughan

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.

# 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions