##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (templatefile, run = F)
{
if (!file.exists(templatefile))
stop("Template file not found.")
readfile <- scan(templatefile, what = "character", sep = "",
strip.white = FALSE)
startinit <- grep("[[init]]", readfile, fixed = T)
endinit <- grep("[[/init]]", readfile, fixed = T)
if (length(startinit) != 1 || length(endinit) != 1) {
stop("Unable to find init section in template file.")
}
initsection <- readfile[(startinit + 1):(endinit - 1)]
bodysection <- readfile[(endinit + 1):length(readfile)]
toProcess <- processInit(initsection)
toProcess$.allTags <- grep("\[\[\s*[\w=><!#]+\s*\]\]",
bodysection, perl = T)
regexp <- paste("\[\[\s*(?!", paste(toProcess$iterators,
collapse = "|"), ")\w+\s*\]\]", sep = "")
toProcess$.simpleTags <- grep(regexp, bodysection[toProcess$.allTags],
perl = T)
bodysection[toProcess$.allTags][toProcess$.simpleTags] <- replaceTags(regexp,
bodysection[toProcess$.allTags][toProcess$.simpleTags],
toProcess, replaceType = "simple")
if (length(toProcess$iterators) > 0) {
recurseReplace(bodysection, toProcess)
}
}
Run the code above in your browser using DataLab