R/representation_as_function.R

Defines functions representation_as_function

#' Get a distribution's representation as a function
#'
#' @param distribution Distribution to extract a representation from.
#' @param representation Character, such as `"cdf"`. In general, a suffix
#' to an `eval_` function. Vector of length 1.
#' @returns A function of the representation.
#' @noRd
representation_as_function <- function(distribution, representation) {
  checkmate::assert_class(distribution, "dst")
  checkmate::assert_character(representation, len = 1)
  f <- distribution[[representation]]
  if (is.null(f)) {
    f <- \(x) eval_property(distribution, representation, x)
  }
  f
}
vincenzocoia/distionary documentation built on April 5, 2025, 5:20 a.m.