Created
October 1, 2024 20:05
-
-
Save JosiahParry/7d953f4af6848e7012566f7abfc63473 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
str_replace_many <- function(string, ...) { | |
replacements <- rlang::list2(...) | |
patterns <- rlang::names2(replacements) | |
if (anyNA(patterns) || any(!nzchar(patterns))) { | |
cli::cli_abort("All arguments passed to {.arg ...} must be named") | |
} | |
for (pattern in replacements) { | |
rlang:::check_string(pattern, arg = pattern) | |
} | |
stringr::str_replace_all(string, unlist(replacements)) | |
} | |
str_replace_many("del hello wor!d", "del " = "", "!" = "l") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment