I would like to use the sprintf
function in R with a variable number of arguments. Can I bundle these arguments together in a character vector or list in order to avoid supplying these arguments to sprintf
individually?
An example will clarify:
base_string = "(1) %s, (2) %s, (3) %s"
sprintf(base_string, "foo", "bar", "baz") # this works
sprintf(base_string, c("foo", "bar", "baz")) # this doesn't work
In Python I can accomplish this with
base_string = "(1) %s, (2) %s, (3) %s"
base_string % ("foo", "bar", "baz")