R/update.R

Defines functions update.rmd_doc

Documented in update.rmd_doc

#' @name update
#'
#' @title Update an rmd_doc
#'
#' @description
#' Alternative to modify settings and content in `rmd_doc` objects. Note that to
#' skip some elements of the YAML header, you can set the argument NULL to the
#' respective parameter.
#'
#' @param object An object of class `rmd_doc`.
#' @param ... Named arguments to be inserted in the YAML header (passed to
#'     [write_rmd()]).
#'
#' @example examples/update.R
#'
#' @method update rmd_doc
#' @export
update.rmd_doc <- function(object, ...) {
  new_values <- list(...)
  for (i in names(new_values)[!names(new_values) %in% c("body")]) {
    object$header[[i]] <- new_values[[i]]
  }
  if ("body" %in% names(new_values)) {
    object$body <- new_values$body
  }
  return(object)
}

Try the yamlme package in your browser

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

yamlme documentation built on Nov. 10, 2022, 5:10 p.m.