R Equivalent of Python str.format

Viewed 72

For this code below ( in python) What is the equivalent code in R?

print("Sammy is a {}, {}, and {} {}!".format("happy", "smiling", "blue", "shark"))
1 Answers

There are multiple ways. We may use sprintf from base R

sprintf("Sammy is a %s, %s and %s %s!", "happy", "smiling", "blue", "shark")
[1] "Sammy is a happy, smiling and blue shark!"

Or may use paste/glue considering these are objects created in the global env

Related