As described in r - Automation of conversion from .Rnw to .Rmd - Stack Overflow I want to take a R no-web
file and apply a series of regular expression replacements to it to create a R markdown
file. Suppose that I had a vector of pairs of the form r"foo" => s"bar"
. What would be a good method of applying them in sequence to a String
so that the value of the n
th replace
call becomes the first argument to the n+1
st call?
Maybe a for-loop?
const REPLACEMENTS = [
r"foo" => s"baz"
r"bar" => s"buz"
r"buz" => s"inga"
]
function do_replace(s)
for rs in REPLACEMENTS
s = replace(s, rs)
end
return s
end
julia> do_replace("foobar")
"bazinga"
1 Like
Thanks. That is more-or-less the approach I settled on.