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

Doc clarification for str_subset about dropping names. #507

Closed
Ax3man opened this issue Apr 18, 2023 · 2 comments · Fixed by #560
Closed

Doc clarification for str_subset about dropping names. #507

Ax3man opened this issue Apr 18, 2023 · 2 comments · Fixed by #560
Labels
bug an unexpected problem or unintended behavior tidy-dev-day 🤓 Tidyverse Developer Day rstd.io/tidy-dev-day

Comments

@Ax3man
Copy link

Ax3man commented Apr 18, 2023

str_subset drops names. This appears to a design choice from stringi (gagolews/stringi#59). Fair enough.

But I got bitten by this today, as I read the documentation stating: "It's a wrapper around x[str_detect(x, pattern)], and is equivalent to grep(pattern, x, value = TRUE)." But both those alternatives do keep names, and there is no other mention of dropping attributes. I suggest to add "but without preserving attributes like names", or something similar.

Consider:

fruit <- c(A = "apple", B = "banana", C = "pear", D = "pineapple")
str_subset(fruit, "b")
fruit[str_detect(fruit, 'b')]
grep('b', fruit, value = TRUE)
@hadley hadley added the bug an unexpected problem or unintended behavior label Aug 4, 2023
@hadley
Copy link
Member

hadley commented Aug 4, 2023

I think we can just fix the behaviour.

@hadley hadley added the tidy-dev-day 🤓 Tidyverse Developer Day rstd.io/tidy-dev-day label Jul 15, 2024
@hadley
Copy link
Member

hadley commented Jul 15, 2024

Looks like the easiest way to fix this would be to switch to making str_subset() use [ + str_detect().

edward-burn added a commit to edward-burn/stringr that referenced this issue Aug 15, 2024
thomasp85 pushed a commit that referenced this issue Aug 15, 2024
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 tidy-dev-day 🤓 Tidyverse Developer Day rstd.io/tidy-dev-day
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants