R/render.R

Defines functions render.template render

Documented in render render.template

#' Render contents to file
#'
#' @param viz vizlab object
#' @param data to render
#' @param file file to render to
#' @export
render <- function(viz, data, file) UseMethod("render")

#' Renter template, return output if file not specified
#'
#' @rdname render
#' @importFrom whisker whisker.render
#' @export
render.template <- function(viz, data, file = NULL) {
  partials <- lapply(viz[['partials']], function(x) {
    t <- template(x)
    return(t[['template']])
  })

  out <- whisker.render(template = viz[['template']], data = data, partials = partials)
  if (!is.null(file)) {
    cat(out, file = file)
  } else {
    return(out)
  }
}
USGS-VIZLAB/vizlab documentation built on Nov. 20, 2017, 7:36 p.m.