Is there a function that can be an alternative to paste ? I would like to know if something like this exists in R:
> buildString ( \"Hi {1}, Have a very nice
frankc and DWin are right to point you to sprintf()
.
If for some reason your replacement parts really will be in the form of a vector (i.e. c("Tom", "day")
), you can use do.call()
to pass them in to sprintf()
:
string <- "Hi %s, Have a really nice %s!"
vals <- c("Tom", "day")
do.call(sprintf, as.list(c(string, vals)))
# [1] "Hi Tom, Have a really nice day!"