str_tpl_format <- function(tpl, l){
if("list" %in% class(l)){
listToNameValue <- function(l){
mapply(function(i,j) list(name = j, value = i), l, names(l), SIMPLIFY = FALSE)
}
f <- function(tpl,l){
gsub(paste0("{",l$name,"}"), l$value, tpl, fixed = TRUE)
}
return( Reduce(f,listToNameValue(l), init = tpl))
}
if("data.frame" %in% class(l)){
myTranspose <- function(x) lapply(1:nrow(x), function(i) lapply(l, "[[", i))
return( unlist(lapply(myTranspose(l), function(l, tpl) str_tpl_format(tpl, l), tpl = tpl)) )
}
}
match_replace <- function (v, dic, force = TRUE){
matches <- dic[[2]][match(v, dic[[1]])]
out <- matches
if (!force)
out[is.na(matches)] <- v[is.na(matches)]
out
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.