R/print.BayesMallowsMixtures.R

Defines functions print.BayesMallowsMixtures

Documented in print.BayesMallowsMixtures

#' Print Method for BayesMallowsMixtures Objects
#'
#' The default print method for a \code{BayesMallowsMixtures} object.
#'
#'
#' @param x An object of type \code{BayesMallowsMixtures}, returned from
#'   \code{\link{compute_mallows_mixtures}}.
#'
#' @param ... Other arguments passed to \code{print} (not used).
#'
#' @export
#'
#' @family posterior quantities
print.BayesMallowsMixtures <- function(x, ...) {
  # Note, the first argument must be named x, otherwise R CMD CHECK will
  # issue a warning. This is because print.BayesMallowsMixtures must have the same
  # required arguments as base::print.

  if (!Reduce(`&`, lapply(x, function(x) inherits(x, "BayesMallows")))) {
    stop("All elements of a BayesMallowsMixtures object must be of class BayesMallows.")
  }

  n_clusters <- vapply(x, function(x) x$n_clusters, integer(1))

  cat(
    "Collection of", length(x), "Bayesian Mallows Mixture Models with the following number of mixture components:\n",
    paste0(paste(n_clusters, collapse = ", "), ".")
  )
}

Try the BayesMallows package in your browser

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

BayesMallows documentation built on Nov. 25, 2023, 5:09 p.m.