From 232a83226060605b3a25c3084f5995e84f4cdf38 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Tue, 26 Mar 2024 19:03:46 +0100 Subject: [PATCH] update default args to `assert_forecast_type()` --- R/forecast.R | 11 +++++------ R/get_-functions.R | 16 +++++++++------- man/assert_forecast_type.Rd | 9 ++++----- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/R/forecast.R b/R/forecast.R index 08982939..95732c67 100644 --- a/R/forecast.R +++ b/R/forecast.R @@ -118,7 +118,7 @@ as_forecast.default <- function(data, } # assert forecast type is as expected - assert_forecast_type(data, forecast_type) + assert_forecast_type(data, desired = forecast_type) forecast_type <- get_forecast_type(data) # produce warning if old format is suspected @@ -205,7 +205,7 @@ validate_forecast.default <- function(data, forecast_type = NULL, ...) { #' @keywords check-forecasts validate_forecast.forecast_binary <- function(data, forecast_type = NULL, ...) { data <- validate_general(data) - assert_forecast_type(data, forecast_type) + assert_forecast_type(data, actual = "binary", desired = forecast_type) columns_correct <- test_columns_not_present( data, c("sample_id", "quantile_level") @@ -239,7 +239,7 @@ validate_forecast.forecast_binary <- function(data, forecast_type = NULL, ...) { #' @keywords check-forecasts validate_forecast.forecast_point <- function(data, forecast_type = NULL, ...) { data <- validate_general(data) - assert_forecast_type(data, forecast_type) + assert_forecast_type(data, actual = "point", desired = forecast_type) #nolint start: keyword_quote_linter object_usage_linter input_check <- check_input_point(data$observed, data$predicted) if (!is.logical(input_check)) { @@ -261,7 +261,7 @@ validate_forecast.forecast_point <- function(data, forecast_type = NULL, ...) { validate_forecast.forecast_quantile <- function(data, forecast_type = NULL, ...) { data <- validate_general(data) - assert_forecast_type(data, forecast_type) + assert_forecast_type(data, actual = "quantile", desired = forecast_type) assert_numeric(data$quantile_level, lower = 0, upper = 1) return(data[]) } @@ -271,9 +271,8 @@ validate_forecast.forecast_quantile <- function(data, #' @rdname validate_forecast #' @keywords check-forecasts validate_forecast.forecast_sample <- function(data, forecast_type = NULL, ...) { - data <- validate_general(data) - assert_forecast_type(data, forecast_type) + assert_forecast_type(data, actual = "sample", desired = forecast_type) return(data[]) } diff --git a/R/get_-functions.R b/R/get_-functions.R index af4eff84..fa5af116 100644 --- a/R/get_-functions.R +++ b/R/get_-functions.R @@ -100,20 +100,22 @@ test_forecast_type_is_quantile <- function(data) { #' Assert that forecast type is as expected #' @param data A forecast object as produced by [as_forecast()]. -#' @inheritParams as_forecast +#' @param actual The actual forecast type of the data +#' @param desired The desired forecast type of the data #' @inherit document_assert_functions return #' @importFrom cli cli_abort #' @importFrom checkmate assert_character -assert_forecast_type <- function(data, forecast_type = NULL) { - assert_character(forecast_type, null.ok = TRUE) - desired <- forecast_type - forecast_type <- get_forecast_type(data) - if (!is.null(desired) && desired != forecast_type) { +#' @keywords internal_input_check +assert_forecast_type <- function(data, + actual = get_forecast_type(data), + desired = NULL) { + assert_character(desired, null.ok = TRUE) + if (!is.null(desired) && desired != actual) { #nolint start: object_usage_linter keyword_quote_linter cli_abort( c( "!" = "Forecast type determined by scoringutils based on input: - {.val {forecast_type}}.", + {.val {actual}}.", "i" = "Desired forecast type: {.val {desired}}." ) ) diff --git a/man/assert_forecast_type.Rd b/man/assert_forecast_type.Rd index 2026d695..d060ac8b 100644 --- a/man/assert_forecast_type.Rd +++ b/man/assert_forecast_type.Rd @@ -4,15 +4,14 @@ \alias{assert_forecast_type} \title{Assert that forecast type is as expected} \usage{ -assert_forecast_type(data, forecast_type = NULL) +assert_forecast_type(data, actual = get_forecast_type(data), desired = NULL) } \arguments{ \item{data}{A forecast object as produced by \code{\link[=as_forecast]{as_forecast()}}.} -\item{forecast_type}{(optional) The forecast type you expect the forecasts -to have. If the forecast type as determined by \code{scoringutils} based on the -input does not match this, an error will be thrown. If \code{NULL} (the default), -the forecast type will be inferred from the data.} +\item{actual}{The actual forecast type of the data} + +\item{desired}{The desired forecast type of the data} } \value{ Returns NULL invisibly if the assertion was successful and throws an