Skip to content

Instantly share code, notes, and snippets.

@kevinushey
Last active December 15, 2015 12:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinushey/5258974 to your computer and use it in GitHub Desktop.
Save kevinushey/5258974 to your computer and use it in GitHub Desktop.
Python style formatting of strings
pymat <- function(string, ...) {
i <- 0
for( arg in list(...) ) {
to_replace <- paste( sep='', "\\{", i, "\\}" )
string <- gsub( to_replace, arg, string )
i <- i + 1
}
return( string )
}
x <- "Mark"
y <- "Banana"
pymat("This is {0}'s {1}.", x, y)
@jonsedar
Copy link

Thanks for this, I'll be using it to simplify some SQL statements in the morning!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment