Last active
December 15, 2015 12:19
-
-
Save kevinushey/5258974 to your computer and use it in GitHub Desktop.
Python style formatting of strings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this, I'll be using it to simplify some SQL statements in the morning!