Skip to content

Enable lambda functions in str_replace_all #331

@k5cents

Description

@k5cents

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions