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

Enable lambda functions in str_replace_all #331

Closed
k5cents opened this issue Feb 10, 2020 · 1 comment
Closed

Enable lambda functions in str_replace_all #331

k5cents opened this issue Feb 10, 2020 · 1 comment
Labels
feature a feature request or enhancement

Comments

@k5cents
Copy link

k5cents commented Feb 10, 2020

Because of how useful and prevalent the purrr-style lambda functions are, I've gotten used to them working across the tidyverse. Just ran into this usage where they aren't supported. I see stringr doesn't import rlang for as_mapper(), so this might not be possible.

library(stringr)
x <- c("[0,3)", "[12,100)", "[9,12)", "[3,6)", "[6,9)")
str_replace_all(x, "\\d+", function(p) as.numeric(p)/100)
#> [1] "[0,0.03)"    "[0.12,1)"    "[0.09,0.12)" "[0.03,0.06)" "[0.06,0.09)"
str_replace_all(x, "\\d+", ~as.numeric(.)/100)
#> Error: `replacement` must be a character vector

Created on 2020-02-10 by the reprex package (v0.3.0)

@hadley
Copy link
Member

hadley commented Apr 20, 2020

Yeah, this would add a dependency on rlang, so I'm not sure it's worth it.

@hadley hadley added the feature a feature request or enhancement label Apr 20, 2020
@hadley hadley closed this as completed in 0fddeef Apr 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants