R/report_priors.R

Defines functions print.report_priors summary.report_priors as.report_priors report_priors

Documented in as.report_priors report_priors

#' Report priors of Bayesian models
#'
#' Reports priors of Bayesian models (see list of supported objects in
#' [report()]).
#'
#' @inheritParams report
#' @inheritParams report_table
#' @inheritParams report_text
#' @inheritParams as.report
#'
#' @return An object of class [report_priors()].
#'
#' @examplesIf requireNamespace("rstanarm", quietly = TRUE)
#' \donttest{
#' # Bayesian models
#' library(rstanarm)
#' model <- stan_glm(mpg ~ disp, data = mtcars, refresh = 0, iter = 1000)
#' r <- report_priors(model)
#' r
#' summary(r)
#' }
#' @export
report_priors <- function(x, ...) {
  UseMethod("report_priors")
}



# METHODS -----------------------------------------------------------------


#' @rdname as.report
#' @export
as.report_priors <- function(x, summary = NULL, ...) {
  class(x) <- unique(c("report_priors", class(x)))
  attributes(x) <- c(attributes(x), list(...))

  if (!is.null(summary)) {
    attr(x, "summary") <- summary
  }
  x
}


#' @export
summary.report_priors <- function(object, ...) {
  if (is.null(attributes(object)$summary)) {
    object
  } else {
    attributes(object)$summary
  }
}

#' @export
print.report_priors <- function(x, ...) {
  cat(paste0(x, collapse = "\n"))
}

Try the report package in your browser

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

report documentation built on Sept. 11, 2024, 8:47 p.m.