Skip to content

Commit

Permalink
Merge branch 'main' into fix-printing-issue
Browse files Browse the repository at this point in the history
  • Loading branch information
nikosbosse authored Oct 30, 2024
2 parents 9f43c9d + b96def0 commit d50c725
Show file tree
Hide file tree
Showing 51 changed files with 132 additions and 135 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Authors@R: c(
email = "[email protected]",
comment = c(ORCID = "0000-0003-0787-087X")))
Description:
scoringutils facilitates the evaluation of forecasts in a convenient
Facilitate the evaluation of forecasts in a convenient
framework based on data.table. It allows user to to check their forecasts
and diagnose issues, to visualise forecasts and missing data, to transform
data before scoring, to handle missing forecasts, to aggregate scores, and
Expand Down
6 changes: 3 additions & 3 deletions R/check-input-helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' If the object is not a data table, it is converted to one. If the object
#' is a data table, a copy of the object is returned.
#' @param data An object to ensure is a data table.
#' @return A data.table/a copy of an existing data.table.
#' @returns A data.table/a copy of an existing data.table.
#' @keywords internal
#' @importFrom data.table copy is.data.table as.data.table
ensure_data.table <- function(data) {
Expand Down Expand Up @@ -101,7 +101,7 @@ check_columns_present <- function(data, columns) {
#' one or more columns are missing, the function returns FALSE. If all columns
#' are present, the function returns TRUE.
#' @inheritParams document_check_functions
#' @return Returns TRUE if all columns are present and FALSE otherwise
#' @returns Returns TRUE if all columns are present and FALSE otherwise
#' @keywords internal_input_check
test_columns_present <- function(data, columns) {
check <- check_columns_present(data, columns)
Expand All @@ -113,7 +113,7 @@ test_columns_present <- function(data, columns) {
#' If none of the columns are present, the function returns TRUE. If one or
#' more columns are present, the function returns FALSE.
#' @inheritParams document_check_functions
#' @return Returns TRUE if none of the columns are present and FALSE otherwise
#' @returns Returns TRUE if none of the columns are present and FALSE otherwise
#' @importFrom checkmate test_names
#' @keywords internal_input_check
test_columns_not_present <- function(data, columns) {
Expand Down
6 changes: 3 additions & 3 deletions R/class-forecast-binary.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ score.forecast_binary <- function(forecast, metrics = get_metrics(forecast), ...
#' @param exclude A character vector of scoring rules to exclude from the list.
#' If `select` is not `NULL`, this argument is ignored.
#' @param ... unused
#' @return A list of scoring functions.
#' @returns A list of scoring functions.
#' @export
#' @family `get_metrics` functions
#' @family get_metrics functions
#' @keywords handle-metrics
#' @examples
#' get_metrics(example_binary)
Expand Down Expand Up @@ -142,6 +142,6 @@ get_metrics.forecast_binary <- function(x, select = NULL, exclude = NULL, ...) {
#' \item{predicted}{predicted value}
#' }
# nolint start
#' @source \url{https://github.com/european-modelling-hubs/covid19-forecast-hub-europe/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/}
#' @source \url{https://github.com/european-modelling-hubs/covid19-forecast-hub-europe_archive/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/}
# nolint end
"example_binary"
4 changes: 2 additions & 2 deletions R/class-forecast-nominal.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ score.forecast_nominal <- function(forecast, metrics = get_metrics(forecast), ..
#' For nominal forecasts, the default scoring rule is:
#' - "log_score" = [logs_nominal()]
#' @export
#' @family `get_metrics` functions
#' @family get_metrics functions
#' @keywords handle-metrics
#' @examples
#' get_metrics(example_nominal)
Expand Down Expand Up @@ -150,6 +150,6 @@ get_metrics.forecast_nominal <- function(x, select = NULL, exclude = NULL, ...)
#' \item{horizon}{forecast horizon in weeks}
#' }
# nolint start
#' @source \url{https://github.com/european-modelling-hubs/covid19-forecast-hub-europe/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/}
#' @source \url{https://github.com/european-modelling-hubs/covid19-forecast-hub-europe_archive/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/}
# nolint end
"example_nominal"
4 changes: 2 additions & 2 deletions R/class-forecast-point.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ score.forecast_point <- function(forecast, metrics = get_metrics(forecast), ...)
#' @inheritSection illustration-input-metric-binary-point Input format
#' @inheritParams get_metrics.forecast_binary
#' @export
#' @family `get_metrics` functions
#' @family get_metrics functions
#' @keywords handle-metrics
#' @examples
#' get_metrics(example_point, select = "ape")
Expand Down Expand Up @@ -160,6 +160,6 @@ get_metrics.forecast_point <- function(x, select = NULL, exclude = NULL, ...) {
#' \item{horizon}{forecast horizon in weeks}
#' }
# nolint start
#' @source \url{https://github.com/european-modelling-hubs/covid19-forecast-hub-europe/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/}
#' @source \url{https://github.com/european-modelling-hubs/covid19-forecast-hub-europe_archive/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/}
# nolint end
"example_point"
4 changes: 2 additions & 2 deletions R/class-forecast-quantile.R
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ score.forecast_quantile <- function(forecast, metrics = get_metrics(forecast), .
#' @inheritSection illustration-input-metric-quantile Input format
#' @inheritParams get_metrics.forecast_binary
#' @export
#' @family `get_metrics` functions
#' @family get_metrics functions
#' @keywords handle-metrics
#' @importFrom purrr partial
#' @examples
Expand Down Expand Up @@ -252,6 +252,6 @@ get_pit_histogram.forecast_quantile <- function(forecast, num_bins = NULL,
#' \item{horizon}{forecast horizon in weeks}
#' }
# nolint start
#' @source \url{https://github.com/european-modelling-hubs/covid19-forecast-hub-europe/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/}
#' @source \url{https://github.com/european-modelling-hubs/covid19-forecast-hub-europe_archive/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/}
# nolint end
"example_quantile"
6 changes: 3 additions & 3 deletions R/class-forecast-sample.R
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ score.forecast_sample <- function(forecast, metrics = get_metrics(forecast), ...
#' @inheritSection illustration-input-metric-sample Input format
#' @inheritParams get_metrics.forecast_binary
#' @export
#' @family `get_metrics` functions
#' @family get_metrics functions
#' @keywords handle-metrics
#' @examples
#' get_metrics(example_sample_continuous, exclude = "mad")
Expand Down Expand Up @@ -238,7 +238,7 @@ get_pit_histogram.forecast_sample <- function(forecast, num_bins = 10,
#' \item{sample_id}{id for the corresponding sample}
#' }
# nolint start
#' @source \url{https://github.com/european-modelling-hubs/covid19-forecast-hub-europe/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/}
#' @source \url{https://github.com/european-modelling-hubs/covid19-forecast-hub-europe_archive/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/}
# nolint end
"example_sample_continuous"

Expand Down Expand Up @@ -266,6 +266,6 @@ get_pit_histogram.forecast_sample <- function(forecast, num_bins = 10,
#' \item{sample_id}{id for the corresponding sample}
#' }
# nolint start
#' @source \url{https://github.com/european-modelling-hubs/covid19-forecast-hub-europe/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/}
#' @source \url{https://github.com/european-modelling-hubs/covid19-forecast-hub-europe_archive/commit/a42867b1ea152c57e25b04f9faa26cfd4bfd8fa6/}
# nolint end
"example_sample_discrete"
6 changes: 3 additions & 3 deletions R/class-forecast.R
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ assert_forecast.default <- function(
#' @param data A data.table with forecasts and observed values that should
#' be validated.
#' @inheritParams assert_forecast
#' @return returns the input
#' @returns returns the input
#' @importFrom data.table ':=' is.data.table
#' @importFrom checkmate assert_data_table
#' @importFrom cli cli_abort cli_inform cli_warn
Expand Down Expand Up @@ -279,7 +279,7 @@ clean_forecast <- function(forecast, copy = FALSE, na.omit = FALSE) {
#'
#' @inheritParams as_forecast
#' @param classname name of the class to be created
#' @return An object of the class indicated by `classname`
#' @returns An object of the class indicated by `classname`
#' @export
#' @keywords internal
new_forecast <- function(data, classname) {
Expand Down Expand Up @@ -412,7 +412,7 @@ tail.forecast <- function(x, ...) {
#' @param x A forecast object (a validated data.table with predicted and
#' observed values, see [as_forecast()]).
#' @param ... Additional arguments for [print()].
#' @return Returns `x` invisibly.
#' @returns Returns `x` invisibly.
#' @importFrom cli cli_inform cli_warn col_blue cli_text
#' @export
#' @keywords gain-insights
Expand Down
4 changes: 2 additions & 2 deletions R/class-scores.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' @param ... Additional arguments to [data.table::as.data.table()]
#' @keywords internal
#' @importFrom data.table as.data.table setattr
#' @return An object of class `scores`
#' @returns An object of class `scores`
#' @examples
#' \dontrun{
#' df <- data.frame(
Expand Down Expand Up @@ -108,7 +108,7 @@ assert_scores <- function(scores) {
#' Character vector with the names of the scoring rules that were used
#' for scoring.
#' @keywords handle-metrics
#' @family `get_metrics` functions
#' @family get_metrics functions
#' @export
get_metrics.scores <- function(x, error = FALSE, ...) {
assert_data_frame(x)
Expand Down
2 changes: 1 addition & 1 deletion R/documentation-templates.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ NULL
#' @param observed Input to be checked. Should be a numeric vector with the
#' observed values of size n.
#' @param columns A character vector of column names to check
#' @return Returns TRUE if the check was successful and a string with an
#' @returns Returns TRUE if the check was successful and a string with an
#' error message otherwise.
#' @name document_check_functions
#' @keywords internal
Expand Down
2 changes: 1 addition & 1 deletion R/forecast-unit.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#' @param forecast_unit Character vector with the names of the columns that
#' uniquely identify a single forecast.
#' @importFrom cli cli_warn
#' @return A data.table with only those columns kept that are relevant to
#' @returns A data.table with only those columns kept that are relevant to
#' scoring or denote the unit of a single forecast as specified by the user.
#' @importFrom data.table ':=' is.data.table copy
#' @importFrom checkmate assert_character assert_subset
Expand Down
2 changes: 1 addition & 1 deletion R/get-correlations.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ get_correlations <- function(scores,
#' @importFrom data.table setDT melt
#' @importFrom checkmate assert_data_frame
#' @export
#' @return A ggplot object with a visualisation of correlations between metrics
#' @returns A ggplot object with a visualisation of correlations between metrics
#' @examples
#' library(magrittr) # pipe operator
#' scores <- example_quantile %>%
Expand Down
4 changes: 2 additions & 2 deletions R/get-coverage.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ get_coverage <- function(forecast, by = "model") {
#' [get_coverage()].
#' @param colour According to which variable shall the graphs be coloured?
#' Default is "model".
#' @return ggplot object with a plot of interval coverage
#' @returns ggplot object with a plot of interval coverage
#' @importFrom ggplot2 ggplot scale_colour_manual scale_fill_manual .data
#' facet_wrap facet_grid geom_polygon geom_line xlab ylab
#' @importFrom checkmate assert_subset
Expand Down Expand Up @@ -178,7 +178,7 @@ plot_interval_coverage <- function(coverage,
#' @inheritParams plot_interval_coverage
#' @param colour String, according to which variable shall the graphs be
#' coloured? Default is "model".
#' @return A ggplot object with a plot of interval coverage
#' @returns A ggplot object with a plot of interval coverage
#' @importFrom ggplot2 ggplot scale_colour_manual scale_fill_manual .data aes
#' scale_y_continuous geom_line
#' @importFrom checkmate assert_subset assert_data_frame
Expand Down
2 changes: 1 addition & 1 deletion R/get-duplicate-forecasts.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' @inheritParams as_forecast
#' @param counts Should the output show the number of duplicates per forecast
#' unit instead of the individual duplicated rows? Default is `FALSE`.
#' @return A data.frame with all rows for which a duplicate forecast was found
#' @returns A data.frame with all rows for which a duplicate forecast was found
#' @export
#' @importFrom checkmate assert_data_frame assert_subset
#' @importFrom data.table setorderv
Expand Down
4 changes: 2 additions & 2 deletions R/get-forecast-counts.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#' `collapse = c()` would mean that all quantiles / samples would be counted
#' as individual forecasts.
#'
#' @return A data.table with columns as specified in `by` and an additional
#' @returns A data.table with columns as specified in `by` and an additional
#' column "count" with the number of forecasts.
#'
#' @inheritParams score
Expand Down Expand Up @@ -90,7 +90,7 @@ get_forecast_counts <- function(forecast,
#' are shown on the x-axis.
#' @param show_counts Logical (default is `TRUE`) that indicates whether
#' or not to show the actual count numbers on the plot.
#' @return A ggplot object with a plot of forecast counts
#' @returns A ggplot object with a plot of forecast counts
#' @importFrom ggplot2 ggplot scale_colour_manual scale_fill_manual
#' geom_tile scale_fill_gradient .data
#' @importFrom data.table dcast .I .N
Expand Down
10 changes: 5 additions & 5 deletions R/get-forecast-type.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
#' Character vector of length one with the forecast type.
#' @keywords internal_input_check
get_forecast_type <- function(forecast) {
classname <- class(forecast)[1]
if (grepl("forecast_", classname, fixed = TRUE)) {
type <- gsub("forecast_", "", classname, fixed = TRUE)
return(type)
classname <- class(forecast)
forecast_class <- classname[grepl("forecast_", classname, fixed = TRUE)]
if (length(forecast_class) == 1) {
return(gsub("forecast_", "", forecast_class, fixed = TRUE))
} else {
cli_abort(
"Input is not a valid forecast object
(it's first class should begin with `forecast_`)."
(There should be a single class beginning with `forecast_`)."
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion R/get-pit-histogram.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#' 'location' in the input data and want to have a PIT histogram for
#' every model and location, specify `by = c("model", "location")`.
#' @inheritParams pit_histogram_sample
#' @return A data.table with density values for each bin in the PIT histogram.
#' @returns A data.table with density values for each bin in the PIT histogram.
#' @examples
#' library("ggplot2")
#'
Expand Down
6 changes: 3 additions & 3 deletions R/helper-quantile-interval-range.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#' and upper bounds of the 50% and 90% prediction intervals (corresponding to
#' the 0.25 and 0.75 as well as the 0.05 and 0.095 quantiles).
#' @param ... Arguments
#' @return A data.table with forecasts in an interval format.
#' @returns A data.table with forecasts in an interval format.
#' @keywords internal
quantile_to_interval <- function(...) {
dots <- list(...)
Expand Down Expand Up @@ -142,7 +142,7 @@ quantile_to_interval_numeric <- function(observed,
#'
#' @inheritParams as_forecast_quantile
#' @param keep_quantile_col keep quantile_level column, default is TRUE
#' @return A data.table in a long interval interval range format
#' @returns A data.table in a long interval interval range format
#' @importFrom data.table as.data.table
#' @importFrom stats quantile
#' @keywords internal
Expand Down Expand Up @@ -179,7 +179,7 @@ sample_to_interval_long <- function(data,
#' rounded to 10 decimal places. This is not a problem for the vast majority of
#' use cases, but it is something to be aware of.
#' @param quantile_level A numeric vector of quantile levels of size N.
#' @return a numeric vector of interval ranges of size N
#' @returns a numeric vector of interval ranges of size N
#' @keywords internal
get_range_from_quantile <- function(quantile_level) {
boundary <- ifelse(quantile_level <= 0.5, "lower", "upper")
Expand Down
4 changes: 2 additions & 2 deletions R/metrics-binary.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ NULL
#' } where \eqn{\textrm{outcome} \in \{0, 1\}}{outcome in {0, 1}}, and
#' \eqn{\textrm{prediction} \in [0, 1]}{prediction in [0, 1]} represents
#' the probability that the outcome is equal to 1.
#' @return A numeric vector of size n with the Brier scores
#' @returns A numeric vector of size n with the Brier scores
#' @keywords metric
#' @export
#' @rdname scoring-functions-binary
Expand All @@ -111,7 +111,7 @@ brier_score <- function(observed, predicted) {
#' assigned to the observed value. It is a proper scoring rule. Small values
#' are better (best is zero, worst is infinity).
#'
#' @return A numeric vector of size n with log scores
#' @returns A numeric vector of size n with log scores
#' @importFrom methods hasArg
#' @export
#' @keywords metric
Expand Down
2 changes: 1 addition & 1 deletion R/metrics-nominal.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ assert_input_nominal <- function(observed, predicted, predicted_label) {
#' possible outcomes.
#' @param predicted_label A factor of length N, denoting the outcome that the
#' probabilities in `predicted` correspond to.
#' @return A numeric vector of size n with log scores
#' @returns A numeric vector of size n with log scores
#' @importFrom methods hasArg
#' @export
#' @keywords metric
Expand Down
Loading

0 comments on commit d50c725

Please sign in to comment.