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

str_sort drops vector names attribute #575

Open
warnes opened this issue Nov 1, 2024 · 1 comment
Open

str_sort drops vector names attribute #575

warnes opened this issue Nov 1, 2024 · 1 comment

Comments

@warnes
Copy link

warnes commented Nov 1, 2024

With stringr 1.5.1, the str_sort function strips names from the vector.

Current behavior:

x <- c(A="3", B="2", C="1")
> str(x)
 Named chr [1:3] "3" "2" "1"
 - attr(*, "names")= chr [1:3] "A" "B" "C"
> stringr::str_sort(x)
[1] "1" "2" "3"
> str(stringr::str_sort(x))
 chr [1:3] "1" 

Expected behavior:

x <- c(A="3", B="2", C="1")
> str(x)
 Named chr [1:3] "3" "2" "1"
 - attr(*, "names")= chr [1:3] "A" "B" "C"
> stringr::str_sort(x)
[1] "1" "2" "3"
> str(stringr::str_sort(x))
 Named chr [1:3] "1" "2" "3"
 - attr(*, "names")= chr [1:3] "C" "B" "A"

> sessionInfo()
R version 4.4.1 (2024-06-14)
Platform: x86_64-apple-darwin20
Running under: macOS 15.0.1

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/New_York
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] devtools_2.4.5 usethis_2.2.3

loaded via a namespace (and not attached):
 [1] vctrs_0.6.5       cli_3.6.2         rlang_1.1.4       stringi_1.8.4
 [5] purrr_1.0.2       pkgload_1.3.4     renv_1.0.11       promises_1.3.0
 [9] shiny_1.8.1.1     xtable_1.8-4      glue_1.7.0        htmltools_0.5.8.1
[13] httpuv_1.6.15     pkgbuild_1.4.4    ellipsis_0.3.2    fastmap_1.2.0
[17] lifecycle_1.0.4   memoise_2.0.1     stringr_1.5.1     compiler_4.4.1
[21] miniUI_0.1.1.1    sessioninfo_1.2.2 fs_1.6.4          htmlwidgets_1.6.4
[25] Rcpp_1.0.12       urlchecker_1.0.1  later_1.3.2       tcltk_4.4.1
[29] digest_0.6.36     R6_2.5.1          magrittr_2.0.3    tools_4.4.1
[33] mime_0.12         profvis_0.3.8     remotes_2.5.0     cachem_1.1.0
@jonovik
Copy link

jonovik commented Nov 19, 2024

Same for str_replace_all(). This was fixed recently for str_subset() in #560 , and I would like to see it everywhere it makes sense.

> letters |> rlang::set_names() |> stringr::str_subset("[ae]")
  a   e 
"a" "e" 
> letters |> rlang::set_names() |> stringr::str_replace_all("a", "e")
 [1] "e" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z"

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

2 participants