From 6b004b8de8fef88a4675d8e6ab2143af90e1b5bf Mon Sep 17 00:00:00 2001 From: Nikos Bosse <37978797+nikosbosse@users.noreply.github.com> Date: Mon, 30 Sep 2024 22:35:03 +0200 Subject: [PATCH] #885 - Delete `validate_forecast()` (#921) --- NAMESPACE | 1 - NEWS.md | 2 +- R/forecast.R | 15 --------------- man/validate_forecast.Rd | 33 --------------------------------- tests/testthat/test-forecast.R | 18 ------------------ 5 files changed, 1 insertion(+), 68 deletions(-) delete mode 100644 man/validate_forecast.Rd diff --git a/NAMESPACE b/NAMESPACE index 846c98b15..4db2d9ce6 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -91,7 +91,6 @@ export(theme_scoringutils) export(transform_forecasts) export(underprediction_quantile) export(underprediction_sample) -export(validate_forecast) export(wis) importFrom(Metrics,ae) importFrom(Metrics,ape) diff --git a/NEWS.md b/NEWS.md index d6820db7d..060b75636 100644 --- a/NEWS.md +++ b/NEWS.md @@ -50,7 +50,7 @@ of our [original](https://doi.org/10.48550/arXiv.2205.07090) `scoringutils` pape - The function `interval_score()` was made an internal function rather than being exported to users. We recommend using `wis()` instead. ### (Re-)Validating forecast objects -- To create and validate a new `forecast` object, users can use `as_forecast_()`. To revalidate an existing `forecast` object users can call `assert_forecast()` (which validates the input and returns `invisible(NULL)`. `assert_forecast()` is a generic with methods for the different forecast types. Alternatively, `validate_forecast()` can be used (which calls `assert_forecast()`), which returns the input and is useful in a pipe. Lastly, users can simply print the object to obtain additional information. +- To create and validate a new `forecast` object, users can use `as_forecast_()`. To revalidate an existing `forecast` object users can call `assert_forecast()` (which validates the input and returns `invisible(NULL)`. `assert_forecast()` is a generic with methods for the different forecast types. Alternatively, users can call ``as_forecast_()` again to re-validate a forecast object. Simply printing the object will also provide some additional information. - Users can test whether an object is of class `forecast_*()` using the function `is_forecast()`. Users can also test for a specific `forecast_*` class using the appropriate `is_forecast.forecast_*` method. For example, to check whether an object is of class `forecast_quantile`, you would use you would use `scoringutils:::is_forecast.forecast_quantile()`. ### Pairwise comparisons and relative skill diff --git a/R/forecast.R b/R/forecast.R index bc5e24a19..07838de61 100644 --- a/R/forecast.R +++ b/R/forecast.R @@ -484,21 +484,6 @@ assert_forecast.forecast_nominal <- function( } -#' @title Re-validate an existing forecast object -#' -#' @description -#' The function re-validates an existing forecast object. It is similar to -#' [assert_forecast()], but returns the input data instead of an invisible -#' `NULL`. See [as_forecast()] for details on the expected input formats. -#' @inherit assert_forecast params return examples -#' @export -#' @keywords validate-forecast-object -validate_forecast <- function(forecast, forecast_type = NULL, verbose = TRUE) { - assert_forecast(forecast, forecast_type, verbose) - return(forecast) -} - - #' @title Validation common to all forecast types #' #' @description diff --git a/man/validate_forecast.Rd b/man/validate_forecast.Rd deleted file mode 100644 index 8b24513d9..000000000 --- a/man/validate_forecast.Rd +++ /dev/null @@ -1,33 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/forecast.R -\name{validate_forecast} -\alias{validate_forecast} -\title{Re-validate an existing forecast object} -\usage{ -validate_forecast(forecast, forecast_type = NULL, verbose = TRUE) -} -\arguments{ -\item{forecast}{A forecast object (a validated data.table with predicted and -observed values, see \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{verbose}{Logical. If \code{FALSE} (default is \code{TRUE}), no messages and -warnings will be created.} -} -\value{ -Returns \code{NULL} invisibly. -} -\description{ -The function re-validates an existing forecast object. It is similar to -\code{\link[=assert_forecast]{assert_forecast()}}, but returns the input data instead of an invisible -\code{NULL}. See \code{\link[=as_forecast]{as_forecast()}} for details on the expected input formats. -} -\examples{ -forecast <- as_forecast_binary(example_binary) -assert_forecast(forecast) -} -\keyword{validate-forecast-object} diff --git a/tests/testthat/test-forecast.R b/tests/testthat/test-forecast.R index a116e97f7..b462d20b3 100644 --- a/tests/testthat/test-forecast.R +++ b/tests/testthat/test-forecast.R @@ -271,24 +271,6 @@ test_that("assert_forecast_generic() works as expected with a data.frame", { }) -# ============================================================================== -# validate_forecast() -# ============================================================================== - -test_that("validate_forecast() works as expected", { - # check that validate forecast returns itself - expect_no_condition( - out <- validate_forecast(as_forecast_point(na.omit(example_point))) - ) - expect_true(!is.null(out)) - - expect_equal( - validate_forecast(as_forecast_point(na.omit(example_point))), - as_forecast_point(na.omit(example_point)) - ) -}) - - # ============================================================================== # new_forecast() # ==============================================================================