R/model_rating_table_deprecated.R

Defines functions rating_factors rating_factors2

Documented in rating_factors rating_factors2

#' Deprecated single-model rating table helper
#'
#' @param model glm object produced by `glm()`
#' @param model_data Optional data.frame used to create glm object. If `NULL`,
#'   the function tries to use `model$data`.
#' @param exposure Logical or character. If `TRUE` (default), exposure is added
#'   if it can be inferred from the model. If `FALSE`, no exposure is added.
#'   If a character string is supplied, it is interpreted as the exposure column
#'   name.
#' @param exposure_name Optional name for the exposure column in the output.
#' @param colname name of coefficient column
#' @param exponentiate logical indicating whether or not to exponentiate the
#'   coefficient estimates. Defaults to TRUE.
#' @param round_exposure number of digits for exposure (defaults to 0)
#'
#' @description `r lifecycle::badge('deprecated')`
#'
#' Legacy interface. Prefer [rating_table()] for fitted models in the new
#' workflow, but this function remains available.
#'
#' @return A data frame with rating factor coefficients for one model.
#'
#' @export
#' @keywords internal
rating_factors2 <- function(model, model_data = NULL, exposure = TRUE,
                            exposure_name = NULL,
                            colname = "estimate",
                            exponentiate = TRUE, round_exposure = 0) {
  lifecycle::deprecate_warn("0.8.0", "rating_factors2()", "rating_table()")

  if (!missing(exposure) && is.symbol(substitute(exposure))) {
    exposure <- deparse(substitute(exposure))
  }

  .rating_table_one_model(
    model,
    model_data = model_data,
    exposure = exposure,
    exposure_output = exposure_name,
    colname = colname,
    exponentiate = exponentiate,
    round_exposure = round_exposure
  )
}

#' Deprecated alias for `rating_table()`
#'
#' @description
#' `rating_factors()` is deprecated as of version 0.8.0. Use
#' [rating_table()] instead.
#'
#' @inheritParams rating_table
#' @param exposure_name Deprecated. Use `exposure_output` in [rating_table()]
#'   instead.
#' @param signif_stars Deprecated. Use `significance` in [rating_table()]
#'   instead.
#'
#' @return See [rating_table()].
#'
#' @export
#' @keywords internal
rating_factors <- function(..., model_data = NULL, exposure = TRUE,
                           exposure_name = NULL,
                           signif_stars = FALSE,
                           exponentiate = TRUE, round_exposure = 0) {
  mc <- match.call(expand.dots = FALSE)
  lifecycle::deprecate_warn("0.8.0", "rating_factors()", "rating_table()")

  if (!missing(exposure) && is.symbol(substitute(exposure))) {
    exposure <- deparse(substitute(exposure))
  }

  model_calls <- as.list(mc$...)
  evaluation_env <- list2env(
    list(
      .legacy_model_data = model_data,
      .legacy_exposure = exposure,
      .legacy_exposure_name = exposure_name,
      .legacy_exponentiate = exponentiate,
      .legacy_signif_stars = signif_stars,
      .legacy_round_exposure = round_exposure
    ),
    parent = parent.frame()
  )

  forwarded_call <- as.call(c(
    list(quote(rating_table)),
    model_calls,
    alist(
      model_data = .legacy_model_data,
      exposure = .legacy_exposure,
      exposure_output = .legacy_exposure_name,
      exponentiate = .legacy_exponentiate,
      significance = .legacy_signif_stars,
      round_exposure = .legacy_round_exposure
    )
  ))

  eval(
    forwarded_call,
    envir = evaluation_env
  )
}

Try the insurancerating package in your browser

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

insurancerating documentation built on July 30, 2026, 5:09 p.m.