R/zzz.R

Defines functions register_s3_method .onLoad

.onLoad <- function(...) {
  register_s3_method("stats", "coef", "ml_analysis")
  register_s3_method("stats", "logLik", "ml_analysis")
  invisible()
}

register_s3_method <- function(pkg, generic, class) {
  stopifnot(is.character(pkg), length(pkg) == 1)
  stopifnot(is.character(generic), length(generic) == 1)
  stopifnot(is.character(class), length(class) == 1)

  fun <- get(paste0(generic, ".", class), envir = parent.frame())

  if (pkg %in% loadedNamespaces()) {
    registerS3method(generic, class, fun, envir = asNamespace(pkg))
  }

  setHook(
    packageEvent(pkg, "onLoad"),
    function(...) {
      registerS3method(generic, class, fun, envir = asNamespace(pkg))
    }
  )
}
poissonconsulting/ml documentation built on Jan. 29, 2020, 5:42 p.m.