R/render.template.R

Defines functions render.template

Documented in render.template

#' Render method for "template" class.
#'
#' Rendering is the process of replacing the tags in moustaches by text.
#' 
#' @param x an object of class "template", a model input file with additional
#' extension ".template".
#' @param ... additional parameters.
#'
#' @return Rendered template file.
#'
#' @author Dennis Walvoort
#' 
#' 
#' @importFrom purrr walk
#' @importFrom magrittr %>% %T>%
#' 
#' @export
render.template <- function(x, ...) {
  sub(pattern = "\\.template$", replacement = "", x = x) %T>% 
    purrr::walk(function(x) {
      readLines(paste(x, "template", sep = "."), warn = FALSE) %>% 
        render(...) %>%
        writeLines(x)
    }) %>%
    as.character
}

Try the spup package in your browser

Any scripts or data that you put into this service are public.

spup documentation built on May 1, 2020, 1:07 a.m.