R/zzz.R

Defines functions registerMethods .onLoad

.onLoad <- function(lib, pkg) {
  .render_context <<- new_stack()
  if (getOption("rmarkdown.df_print", TRUE)) {
    registerMethods(list(
      # c(package, genname, class)
      c("knitr", "knit_print", "data.frame")
    ))
  }
}

# Reusable function for registering a set of methods with S3 manually. The
# methods argument is a list of character vectors, each of which has the form
# c(package, genname, class).
registerMethods <- function(methods) {
  lapply(methods, function(method) {
    pkg <- method[[1]]
    generic <- method[[2]]
    class <- method[[3]]
    func <- get(paste(generic, class, sep = "."))
    if (pkg %in% loadedNamespaces()) {
      registerS3method(generic, class, func, envir = asNamespace(pkg))
    }
    setHook(
      packageEvent(pkg, "onLoad"),
      function(...) {
        registerS3method(generic, class, func, envir = asNamespace(pkg))
      }
    )
  })
}

Try the rmarkdown package in your browser

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

rmarkdown documentation built on Nov. 4, 2024, 5:06 p.m.