R/report.R

Defines functions report.mdl_ts report.mdl_df report

Documented in report

#' Report information about an object
#' 
#' Displays the object in a suitable format for reporting.
#' 
#' @param object The object to report
#' @param ... Additional options for the reporting function
#' 
#' @export
report <- function(object, ...){
  UseMethod("report")
}

#' @export
report.mdl_df <- function(object, ...){
  if(NROW(object) > 1 || length(mable_vars(object)) > 1){
    warning("Model reporting is only supported for individual models, so a glance will be shown. To see the report for a specific model, use `select()` and `filter()` to identify a single model.")
    return(glance(object))
  }
  else{
    report(object[[mable_vars(object)[[1]]]][[1]], ...)
  }
  invisible(object)
}

#' @export
report.mdl_ts <- function(object, ...){
  cat(paste("Series:", paste0(map(object$response, expr_name), collapse = ", "), "\n"))
  cat(paste("Model:", model_sum(object), "\n"))
  if(!is_symbol(body(object$transformation[[1]])) && length(object$response) == 1){
    cat(paste("Transformation:", expr_name(body(object$transformation[[1]])), "\n"))
  }
  tryCatch(
    report(object[["fit"]], ...),
    error = function(e){
      cat("\nA model specific report is not available for this model class.")
    }
  )
}

Try the fabletools package in your browser

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

fabletools documentation built on Oct. 12, 2023, 1:07 a.m.