str_replace_verbose | R Documentation |
Applies a series of regular-expression-replacement pairs to one or more strings. All performed replacements are displayed on the console by default
(verbose = TRUE
).
str_replace_verbose(string, pattern, verbose = TRUE, n_context_chrs = 20L)
string |
Input vector. Either a character vector, or something coercible to one. |
pattern |
A named character vector with patterns as names and replacements as values ( |
verbose |
Whether or not to display replacements on the console. |
n_context_chrs |
The (maximum) number of characters displayed around the actual |
This function provides a subset of stringr::str_replace_all()
's functionality. If you don't need the visual console output, it's recommended to directly
resort to the latter.
A character vector.
Other string functions:
str_normalize()
,
str_normalize_file()
,
str_replace_file()
"Make love, not war" |>
yay::str_replace_verbose(pattern = c("love" = "hummus",
"war" = "walls"))
# pattern-replacement pairs are processed one-by-one, so the following gives the same result
"Make love, not war" |>
yay::str_replace_verbose(pattern = c("love" = "hummus",
"hummus, not war" = "hummus, not walls"))
# varying `n_context_chrs` affects console output summarization
input <- c("Tulips are not durable, ",
"not scarce, ",
"not programmable, ",
"not fungible, ",
"not verifiable, ",
"not divisible, ",
"and hard to transfer. ",
"But tell me more about your analogy...",
"",
"-[Naval Ravikant](https://twitter.com/naval/status/939316447318122496)")
pattern <- c("not" = "extremely",
"hard" = "ridiculously easy",
"^But.*" = "So... flower power?",
"(^-).*Naval.*" = "\\1\U0001F92A")
yay::str_replace_verbose(string = input,
pattern = pattern,
n_context_chrs = 5L) |>
pal::cat_lines()
yay::str_replace_verbose(string = input,
pattern = pattern,
n_context_chrs = 0L) |>
pal::cat_lines()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.