diff --git a/NAMESPACE b/NAMESPACE index baee88c7..3c868064 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,10 +5,14 @@ S3method("[",forecast) S3method("[<-",forecast) S3method("[[<-",forecast) S3method(`[`,scores) +S3method(as_forecast_binary,default) +S3method(as_forecast_nominal,default) +S3method(as_forecast_ordinal,default) S3method(as_forecast_point,default) S3method(as_forecast_point,forecast_quantile) S3method(as_forecast_quantile,default) S3method(as_forecast_quantile,forecast_sample) +S3method(as_forecast_sample,default) S3method(assert_forecast,default) S3method(assert_forecast,forecast_binary) S3method(assert_forecast,forecast_nominal) @@ -40,7 +44,6 @@ export(add_relative_skill) export(ae_median_quantile) export(ae_median_sample) export(as_forecast_binary) -export(as_forecast_nominal) export(as_forecast_ordinal) export(as_forecast_point) export(as_forecast_quantile) diff --git a/R/class-forecast-binary.R b/R/class-forecast-binary.R index 09fc1704..0c36ee85 100644 --- a/R/class-forecast-binary.R +++ b/R/class-forecast-binary.R @@ -18,11 +18,11 @@ #' #' See the [example_binary] data set for an example. #' @inheritSection forecast_types Forecast unit +#' @param ... Unused #' @returns A `forecast` object of class `forecast_binary` #' @family functions to create forecast objects -#' @importFrom cli cli_warn -#' @keywords as_forecast #' @export +#' @keywords as_forecast transform #' @examples #' as_forecast_binary( #' example_binary, @@ -30,10 +30,19 @@ #' forecast_unit = c("model", "target_type", "target_end_date", #' "horizon", "location") #' ) -as_forecast_binary <- function(data, - forecast_unit = NULL, - observed = NULL, - predicted = NULL) { +as_forecast_binary <- function(data, ...) { + UseMethod("as_forecast_binary") +} + +#' @rdname as_forecast_binary +#' @export +#' @method as_forecast_binary default +#' @importFrom cli cli_warn +as_forecast_binary.default <- function(data, + forecast_unit = NULL, + observed = NULL, + predicted = NULL, + ...) { data <- as_forecast_generic( data, forecast_unit, @@ -45,7 +54,6 @@ as_forecast_binary <- function(data, return(data) } - #' @export #' @rdname assert_forecast #' @importFrom cli cli_abort diff --git a/R/class-forecast-nominal.R b/R/class-forecast-nominal.R index c589b585..8c076dc5 100644 --- a/R/class-forecast-nominal.R +++ b/R/class-forecast-nominal.R @@ -7,7 +7,8 @@ #' #' # Required input #' -#' The input needs to be a data.frame or similar with the following columns: +#' The input needs to be a data.frame or similar for the default method +#' with the following columns: #' - `observed`: Column with observed values of type `factor` with N levels, #' where N is the number of possible outcomes. #' The levels of the factor represent the possible outcomes that @@ -26,13 +27,11 @@ #' #' See the [example_nominal] data set for an example. #' @inheritSection forecast_types Forecast unit -#' @param predicted_label (optional) Name of the column in `data` that denotes -#' the outcome to which a predicted probability corresponds to. -#' This column will be renamed to "predicted_label". +#' @param ... Unused #' @returns A `forecast` object of class `forecast_nominal` #' @family functions to create forecast objects -#' @keywords as_forecast -#' @export +#' @keywords as_forecast transform +#' @export4 #' @examples #' as_forecast_nominal( #' na.omit(example_nominal), @@ -40,11 +39,23 @@ #' forecast_unit = c("model", "target_type", "target_end_date", #' "horizon", "location") #' ) -as_forecast_nominal <- function(data, - forecast_unit = NULL, - observed = NULL, - predicted = NULL, - predicted_label = NULL) { +as_forecast_nominal <- function(data, ...) { + UseMethod("as_forecast_nominal") +} + +#' @rdname as_forecast_nominal +#' @param predicted_label (optional) Name of the column in `data` that denotes +#' the outcome to which a predicted probability corresponds to. +#' This column will be renamed to "predicted_label". +#' @export +#' @method as_forecast_nominal default +#' @importFrom cli cli_warn +as_forecast_nominal.default <- function(data, + forecast_unit = NULL, + observed = NULL, + predicted = NULL, + predicted_label = NULL, + ...) { data <- as_forecast_generic( data, forecast_unit, diff --git a/R/class-forecast-ordinal.R b/R/class-forecast-ordinal.R index d6dda020..d3bb4d9f 100644 --- a/R/class-forecast-ordinal.R +++ b/R/class-forecast-ordinal.R @@ -7,7 +7,8 @@ #' #' # Required input #' -#' The input needs to be a data.frame or similar with the following columns: +#' The input needs to be a data.frame or similar for the default method +#' with the following columns: #' - `observed`: Column with observed values of type `factor` with N ordered #' levels, where N is the number of possible outcomes. #' The levels of the factor represent the possible outcomes that @@ -26,13 +27,11 @@ #' #' See the [example_ordinal] data set for an example. #' @inheritSection forecast_types Forecast unit -#' @param predicted_label (optional) Name of the column in `data` that denotes -#' the outcome to which a predicted probability corresponds to. -#' This column will be renamed to "predicted_label". -#' @returns A `forecast` object of class `forecast_ordinal` +#' @param ... Unused #' @family functions to create forecast objects -#' @keywords as_forecast +#' @returns A `forecast` object of class `forecast_ordinal` #' @export +#' @keywords as_forecast transform #' @examples #' as_forecast_ordinal( #' na.omit(example_ordinal), @@ -40,11 +39,23 @@ #' forecast_unit = c("model", "target_type", "target_end_date", #' "horizon", "location") #' ) -as_forecast_ordinal <- function(data, - forecast_unit = NULL, - observed = NULL, - predicted = NULL, - predicted_label = NULL) { +as_forecast_ordinal <- function(data, ...) { + UseMethod("as_forecast_ordinal") +} + +#' @rdname as_forecast_ordinal +#' @param predicted_label (optional) Name of the column in `data` that denotes +#' the outcome to which a predicted probability corresponds to. +#' This column will be renamed to "predicted_label". +#' @export +#' @method as_forecast_ordinal default +#' @importFrom cli cli_warn +as_forecast_ordinal.default <- function(data, + forecast_unit = NULL, + observed = NULL, + predicted = NULL, + predicted_label = NULL, + ...) { data <- as_forecast_generic( data, forecast_unit, diff --git a/R/class-forecast-point.R b/R/class-forecast-point.R index 7e2aa9eb..2cda639c 100644 --- a/R/class-forecast-point.R +++ b/R/class-forecast-point.R @@ -3,7 +3,8 @@ #' @details #' # Required input #' -#' The input needs to be a data.frame or similar with the following columns: +#' The input needs to be a data.frame or similar for the default method +#' with the following columns: #' - `observed`: Column of type `numeric` with observed values. #' - `predicted`: Column of type `numeric` with predicted values. #' @@ -24,6 +25,7 @@ as_forecast_point <- function(data, ...) { #' @rdname as_forecast_point #' @export +#' @method as_forecast_point default #' @importFrom cli cli_warn as_forecast_point.default <- function(data, forecast_unit = NULL, diff --git a/R/class-forecast-quantile.R b/R/class-forecast-quantile.R index ac341ee2..169b52a1 100644 --- a/R/class-forecast-quantile.R +++ b/R/class-forecast-quantile.R @@ -3,7 +3,8 @@ #' @details #' # Required input #' -#' The input needs to be a data.frame or similar with the following columns: +#' The input needs to be a data.frame or similar for the default method +#' with the following columns: #' - `observed`: Column of type `numeric` with observed values. #' - `predicted`: Column of type `numeric` with predicted values. Predicted #' values represent quantiles of the predictive distribution. @@ -39,6 +40,7 @@ as_forecast_quantile <- function(data, ...) { #' the quantile level of the predicted values. This column will be renamed to #' "quantile_level". Only applicable to quantile-based forecasts. #' @export +#' @method as_forecast_quantile default #' @importFrom cli cli_warn as_forecast_quantile.default <- function(data, forecast_unit = NULL, diff --git a/R/class-forecast-sample.R b/R/class-forecast-sample.R index 8252ca4d..a427a979 100644 --- a/R/class-forecast-sample.R +++ b/R/class-forecast-sample.R @@ -3,7 +3,8 @@ #' @details #' # Required input #' -#' The input needs to be a data.frame or similar with the following columns: +#' The input needs to be a data.frame or similar for the default method +#' with the following columns: #' - `observed`: Column of type `numeric` with observed values. #' - `predicted`: Column of type `numeric` with predicted values. Predicted #' values represent random samples from the predictive distribution. @@ -17,18 +18,27 @@ #' See the [example_sample_continuous] and [example_sample_discrete] data set #' for an example #' @inheritSection forecast_types Forecast unit +#' @param ... Unused +#' @family functions to create forecast objects +#' @returns A `forecast` object of class `forecast_sample` +#' @export +#' @keywords as_forecast transform +as_forecast_sample <- function(data, ...) { + UseMethod("as_forecast_sample") +} + + +#' @rdname as_forecast_sample #' @param sample_id (optional) Name of the column in `data` that contains the #' sample id. This column will be renamed to "sample_id". #' @export -#' @returns A `forecast` object of class `forecast_sample` -#' @family functions to create forecast objects #' @importFrom cli cli_warn -#' @keywords as_forecast -as_forecast_sample <- function(data, - forecast_unit = NULL, - observed = NULL, - predicted = NULL, - sample_id = NULL) { +as_forecast_sample.default <- function(data, + forecast_unit = NULL, + observed = NULL, + predicted = NULL, + sample_id = NULL, + ...) { data <- as_forecast_generic( data, forecast_unit, diff --git a/man/as_forecast_binary.Rd b/man/as_forecast_binary.Rd index 73dd4213..ac33fc81 100644 --- a/man/as_forecast_binary.Rd +++ b/man/as_forecast_binary.Rd @@ -2,13 +2,17 @@ % Please edit documentation in R/class-forecast-binary.R \name{as_forecast_binary} \alias{as_forecast_binary} +\alias{as_forecast_binary.default} \title{Create a \code{forecast} object for binary forecasts} \usage{ -as_forecast_binary( +as_forecast_binary(data, ...) + +\method{as_forecast_binary}{default}( data, forecast_unit = NULL, observed = NULL, - predicted = NULL + predicted = NULL, + ... ) } \arguments{ @@ -16,6 +20,8 @@ as_forecast_binary( See the details section of for additional information on the required input format.} +\item{...}{Unused} + \item{forecast_unit}{(optional) Name of the columns in \code{data} (after any renaming of columns) that denote the unit of a single forecast. See \code{\link[=get_forecast_unit]{get_forecast_unit()}} for details. @@ -107,3 +113,4 @@ Other functions to create forecast objects: } \concept{functions to create forecast objects} \keyword{as_forecast} +\keyword{transform} diff --git a/man/as_forecast_nominal.Rd b/man/as_forecast_nominal.Rd index a578a422..f332d5de 100644 --- a/man/as_forecast_nominal.Rd +++ b/man/as_forecast_nominal.Rd @@ -2,14 +2,18 @@ % Please edit documentation in R/class-forecast-nominal.R \name{as_forecast_nominal} \alias{as_forecast_nominal} +\alias{as_forecast_nominal.default} \title{Create a \code{forecast} object for nominal forecasts} \usage{ -as_forecast_nominal( +as_forecast_nominal(data, ...) + +\method{as_forecast_nominal}{default}( data, forecast_unit = NULL, observed = NULL, predicted = NULL, - predicted_label = NULL + predicted_label = NULL, + ... ) } \arguments{ @@ -17,6 +21,8 @@ as_forecast_nominal( See the details section of for additional information on the required input format.} +\item{...}{Unused} + \item{forecast_unit}{(optional) Name of the columns in \code{data} (after any renaming of columns) that denote the unit of a single forecast. See \code{\link[=get_forecast_unit]{get_forecast_unit()}} for details. @@ -55,7 +61,8 @@ generalisation of binary forecasts to multiple outcomes. The possible outcomes that the observed values can assume are not ordered. } \section{Required input}{ -The input needs to be a data.frame or similar with the following columns: +The input needs to be a data.frame or similar for the default method +with the following columns: \itemize{ \item \code{observed}: Column with observed values of type \code{factor} with N levels, where N is the number of possible outcomes. @@ -121,3 +128,4 @@ Other functions to create forecast objects: } \concept{functions to create forecast objects} \keyword{as_forecast} +\keyword{transform} diff --git a/man/as_forecast_ordinal.Rd b/man/as_forecast_ordinal.Rd index bfff8cff..2ba17ec1 100644 --- a/man/as_forecast_ordinal.Rd +++ b/man/as_forecast_ordinal.Rd @@ -2,14 +2,18 @@ % Please edit documentation in R/class-forecast-ordinal.R \name{as_forecast_ordinal} \alias{as_forecast_ordinal} +\alias{as_forecast_ordinal.default} \title{Create a \code{forecast} object for ordinal forecasts} \usage{ -as_forecast_ordinal( +as_forecast_ordinal(data, ...) + +\method{as_forecast_ordinal}{default}( data, forecast_unit = NULL, observed = NULL, predicted = NULL, - predicted_label = NULL + predicted_label = NULL, + ... ) } \arguments{ @@ -17,6 +21,8 @@ as_forecast_ordinal( See the details section of for additional information on the required input format.} +\item{...}{Unused} + \item{forecast_unit}{(optional) Name of the columns in \code{data} (after any renaming of columns) that denote the unit of a single forecast. See \code{\link[=get_forecast_unit]{get_forecast_unit()}} for details. @@ -55,7 +61,8 @@ generalisation of binary forecasts to multiple outcomes. The possible outcomes that the observed values can assume are ordered. } \section{Required input}{ -The input needs to be a data.frame or similar with the following columns: +The input needs to be a data.frame or similar for the default method +with the following columns: \itemize{ \item \code{observed}: Column with observed values of type \code{factor} with N ordered levels, where N is the number of possible outcomes. @@ -121,3 +128,4 @@ Other functions to create forecast objects: } \concept{functions to create forecast objects} \keyword{as_forecast} +\keyword{transform} diff --git a/man/as_forecast_point.Rd b/man/as_forecast_point.Rd index 7cf164b1..484c4695 100644 --- a/man/as_forecast_point.Rd +++ b/man/as_forecast_point.Rd @@ -47,7 +47,8 @@ When converting a \code{forecast_quantile} object into a \code{forecast_point} o the 0.5 quantile is extracted and returned as the point forecast. } \section{Required input}{ -The input needs to be a data.frame or similar with the following columns: +The input needs to be a data.frame or similar for the default method +with the following columns: \itemize{ \item \code{observed}: Column of type \code{numeric} with observed values. \item \code{predicted}: Column of type \code{numeric} with predicted values. diff --git a/man/as_forecast_quantile.Rd b/man/as_forecast_quantile.Rd index cc971666..de012aec 100644 --- a/man/as_forecast_quantile.Rd +++ b/man/as_forecast_quantile.Rd @@ -72,7 +72,8 @@ the columns that uniquely identify a single forecast (and thereby removing other, unneeded columns. See section "Forecast Unit" below for details). } \section{Required input}{ -The input needs to be a data.frame or similar with the following columns: +The input needs to be a data.frame or similar for the default method +with the following columns: \itemize{ \item \code{observed}: Column of type \code{numeric} with observed values. \item \code{predicted}: Column of type \code{numeric} with predicted values. Predicted diff --git a/man/as_forecast_sample.Rd b/man/as_forecast_sample.Rd index 3ea3d393..b3ebb237 100644 --- a/man/as_forecast_sample.Rd +++ b/man/as_forecast_sample.Rd @@ -2,14 +2,18 @@ % Please edit documentation in R/class-forecast-sample.R \name{as_forecast_sample} \alias{as_forecast_sample} +\alias{as_forecast_sample.default} \title{Create a \code{forecast} object for sample-based forecasts} \usage{ -as_forecast_sample( +as_forecast_sample(data, ...) + +\method{as_forecast_sample}{default}( data, forecast_unit = NULL, observed = NULL, predicted = NULL, - sample_id = NULL + sample_id = NULL, + ... ) } \arguments{ @@ -17,6 +21,8 @@ as_forecast_sample( See the details section of for additional information on the required input format.} +\item{...}{Unused} + \item{forecast_unit}{(optional) Name of the columns in \code{data} (after any renaming of columns) that denote the unit of a single forecast. See \code{\link[=get_forecast_unit]{get_forecast_unit()}} for details. @@ -49,7 +55,8 @@ the columns that uniquely identify a single forecast (and thereby removing other, unneeded columns. See section "Forecast Unit" below for details). } \section{Required input}{ -The input needs to be a data.frame or similar with the following columns: +The input needs to be a data.frame or similar for the default method +with the following columns: \itemize{ \item \code{observed}: Column of type \code{numeric} with observed values. \item \code{predicted}: Column of type \code{numeric} with predicted values. Predicted @@ -102,3 +109,4 @@ Other functions to create forecast objects: } \concept{functions to create forecast objects} \keyword{as_forecast} +\keyword{transform}