File: zzz.R

package info (click to toggle)
r-cran-rmarkdown 2.6%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 7,552 kB
  • sloc: javascript: 5,605; sh: 24; makefile: 17
file content (31 lines) | stat: -rw-r--r-- 898 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
.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))
      }
    )
  })
}