foo<-1; bar<-"two"; baz <- "III"
interpolate(c(".(foo),", "a .(bar)", "a .(foo) .(bar) .(baz)"))
interply("hello .(..1)")(c("world", "nurse", "kitty"))
interply("hello {{q}}", begin="{{", end="}}")(q=c("there", "you"))
"hello .(x)" %#% c(x="world")
#shell-style interpolation -- "$" start and no end delim
interply("$hello, ${paste(rep('hello', 3), collapse=' ')}, $'hi'",
begin="$", end=""
)(hello="hola")
# Compliant 99 Bottles implementation:
bottles <- interply(
".(ifelse(n%%100>0, n%%100, 'no more')) bottle.('s'[n%%100!=1]) of beer")
initcap <- function(x) {substr(x, 1, 1) <- toupper(substr(x, 1, 1)); x}
verse <- interply(
paste0(".(initcap(bottles(n=n))) on the wall, .(bottles(n=n)).\n",
".(c('Go to the store and buy some more,',",
" 'Take one down and pass it around,')[(n%%100!=0)+1])",
" .(initcap(bottles(n=n-1))) on the wall."))
cat(verse(n=99:0), sep="\n\n")
Run the code above in your browser using DataLab