using dot-dot-dot (`...`) with `str_replace_all()`

Hi there!
I have a function which is a wrapper around stringr::str_c(), and therefore receives any number of character vectors as input using the ... argument.
The issue is that I would like to perform some preliminary cleaning on these vectors with stringr::str_replace_all() before passing them to str_c(), but str_replace_all() function only recieves a single character vector as string input.

How do I pass ... arguments to str_replace all()?

Please note that I intend to use the replaced version of ... later in my function, so the result of replacement should somehow be saved in a form that can be passed to str_c().

Thanks!

This is inelegant, since it forces the arguments to be realized, but as you've described the issue, it gets the job done:

library(stringr)

f <- function(...) {
  unlist(list(...)) |> 
    str_replace_all("z", "0") |> 
    str_c()
}

f('az', 'bz', 'cz')  # "a0" "b0" "c0"

Thanks!
This indeed does the trick.
If anyone else has any idea on how to do this without realizing the arguments I'll be more than happy, and if not then this would suffice.
I read in Advanced R some things about list2() and exec() but couldn't understand how to use them in this use case.
Thanks again.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.