sprintf

sprintf(fmt, …)
Create a character string that contains values from R objects. (The sprintf is much more robust than is touched on here, but this will provide sufficient info for a basic start.)
  • fmt – A character string with some occurrences of %s, which will be places that object values are inserted.
  • – The R objects to be inserted. The number of items should correspond to the number of %s occurrences in fmt.

Example. Below are two simple examples of using sprintf.
> 
> x <- 2349
> sprintf("Substitute in a string or number: %s", x)
[1] "Substitute in a string or number: 2349"
> 
> sprintf("Can have multiple %s occurrences %s", x, "- got it?")
[1] "Can have multiple 2349 occurrences - got it?"
> 

Leave a Reply