I am more familiar with gsub than substitute . The following works:
words <- "\\frac{A}{B}" numbers <- list(A=5, B=10) arglist = mapply(list, as.list(names(numbers)), numbers, SIMPLIFY=F) for (i in 1:length(arglist)){ arglist[[i]]["x"] <- words words <- do.call("gsub", arglist[[i]]) }
But of course, this is unsafe because you are repeating replacements. If, say, the first variable has the value "B" and the second variable has the name "B", you will have problems. There is probably a cleaner way.
source share