From 945e95b1556f8bf19516e7603accffd7233de1dc Mon Sep 17 00:00:00 2001 From: Sam Abbott Date: Thu, 18 Apr 2024 17:04:58 +0100 Subject: [PATCH 01/10] Update R/summarise_scores.R Co-authored-by: Hugo Gruson <10783929+Bisaloo@users.noreply.github.com> --- R/summarise_scores.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/summarise_scores.R b/R/summarise_scores.R index 29b385aeb..20e9d073b 100644 --- a/R/summarise_scores.R +++ b/R/summarise_scores.R @@ -72,7 +72,7 @@ summarise_scores <- function(scores, # if across is provided, calculate new `by` if (!is.null(across)) { - if (!setequal(by, "model")) { + if (by != "model") { warning("You specified `across` and `by` at the same time.", "`by` will be ignored.") } From b2604093961e47809eed4f6402521c52065e0d5a Mon Sep 17 00:00:00 2001 From: Sam Abbott Date: Thu, 18 Apr 2024 17:42:55 +0100 Subject: [PATCH 02/10] Update R/check-input-helpers.R Co-authored-by: Hugo Gruson <10783929+Bisaloo@users.noreply.github.com> --- R/check-input-helpers.R | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/R/check-input-helpers.R b/R/check-input-helpers.R index 74b70d550..d723f0877 100644 --- a/R/check-input-helpers.R +++ b/R/check-input-helpers.R @@ -177,9 +177,5 @@ test_columns_present <- function(data, columns) { #' @return Returns TRUE if none of the columns are present and FALSE otherwise #' @keywords internal_input_check test_columns_not_present <- function(data, columns) { - if (any(columns %in% colnames(data))) { - return(FALSE) - } else { - return(TRUE) - } + checkmate::test_names(colnames(data), disjunct.from = columns) } From 7f65176efb64473f30da61ad0ed37010df96f55f Mon Sep 17 00:00:00 2001 From: Sam Abbott Date: Thu, 18 Apr 2024 17:43:27 +0100 Subject: [PATCH 03/10] Update R/default-scoring-rules.R Co-authored-by: Hugo Gruson <10783929+Bisaloo@users.noreply.github.com> --- R/default-scoring-rules.R | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/R/default-scoring-rules.R b/R/default-scoring-rules.R index c4de4ea41..9896f9102 100644 --- a/R/default-scoring-rules.R +++ b/R/default-scoring-rules.R @@ -29,14 +29,15 @@ select_metrics <- function(metrics, select = NULL, exclude = NULL) { if (is.null(select) && is.null(exclude)) { return(metrics) - } else if (is.null(select)) { + } + if (is.null(select)) { assert_subset(exclude, allowed) select <- allowed[!allowed %in% exclude] return(metrics[select]) - } else { - assert_subset(select, allowed) - return(metrics[select]) } + assert_subset(select, allowed) + return(metrics[select]) + } #' Customises a metric function with additional arguments. From 5e56a0c87854062b430f99e8d9ad370fe4aca86b Mon Sep 17 00:00:00 2001 From: Sam Abbott Date: Thu, 18 Apr 2024 17:43:44 +0100 Subject: [PATCH 04/10] Update R/check-input-helpers.R Co-authored-by: Hugo Gruson <10783929+Bisaloo@users.noreply.github.com> --- R/check-input-helpers.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/check-input-helpers.R b/R/check-input-helpers.R index d723f0877..425f85336 100644 --- a/R/check-input-helpers.R +++ b/R/check-input-helpers.R @@ -166,7 +166,7 @@ check_columns_present <- function(data, columns) { #' @keywords internal_input_check test_columns_present <- function(data, columns) { check <- check_columns_present(data, columns) - return(is.logical(check)) + return(isTRUE(check)) } #' Test whether column names are NOT present in a data.frame From 4d69b2b854b5aa031da3132127c953fa506d8cdf Mon Sep 17 00:00:00 2001 From: Sam Abbott Date: Thu, 18 Apr 2024 17:44:09 +0100 Subject: [PATCH 05/10] Update DESCRIPTION Co-authored-by: Hugo Gruson <10783929+Bisaloo@users.noreply.github.com> --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index c7345338a..29ebf9880 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -15,7 +15,7 @@ Authors@R: c( person(given = "Hugo", family = "Gruson", role = c("aut"), - email = "hugo.gruson@lshtm.ac.uk", + email = "hugo.gruson+R@normalesup.org", comment = c(ORCID = "https://orcid.org/0000-0002-4094-1476")), person(given = "Johannes Bracher", role = c("ctb"), From fd8984224675df40851770ff26ef1512c4376c6f Mon Sep 17 00:00:00 2001 From: Sam Abbott Date: Thu, 18 Apr 2024 17:44:44 +0100 Subject: [PATCH 06/10] Update R/check-inputs-scoring-functions.R Co-authored-by: Hugo Gruson <10783929+Bisaloo@users.noreply.github.com> --- R/check-inputs-scoring-functions.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/check-inputs-scoring-functions.R b/R/check-inputs-scoring-functions.R index bb7487887..036f34423 100644 --- a/R/check-inputs-scoring-functions.R +++ b/R/check-inputs-scoring-functions.R @@ -21,7 +21,7 @@ assert_input_sample <- function(observed, predicted) { check_matrix(predicted, mode = "numeric", nrows = n_obs) ) } else { - assert(check_matrix(predicted, mode = "numeric", nrows = n_obs)) + assert_matrix(predicted, mode = "numeric", nrows = n_obs) } return(invisible(NULL)) } From 4129e2f9a3b1cbda45fdb803d0ae2cec7485ece9 Mon Sep 17 00:00:00 2001 From: Sam Abbott Date: Thu, 18 Apr 2024 17:45:10 +0100 Subject: [PATCH 07/10] Update R/convenience-functions.R Co-authored-by: Hugo Gruson <10783929+Bisaloo@users.noreply.github.com> --- R/convenience-functions.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/convenience-functions.R b/R/convenience-functions.R index 56ee1abac..e4f19d3ef 100644 --- a/R/convenience-functions.R +++ b/R/convenience-functions.R @@ -127,7 +127,7 @@ transform_forecasts <- function(forecast, #nolint start: keyword_quote_linter cli_abort( c( - "!" = "If a column 'scale' is present, entries with scale =='natural' + `!` = "If a column 'scale' is present, entries with scale =='natural' are required for the transformation." ) ) From 980a14d523ae55dca5ffb81656649a5a5e119d3d Mon Sep 17 00:00:00 2001 From: Sam Abbott Date: Thu, 18 Apr 2024 17:45:51 +0100 Subject: [PATCH 08/10] Update R/print.R Co-authored-by: Hugo Gruson <10783929+Bisaloo@users.noreply.github.com> --- R/print.R | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/R/print.R b/R/print.R index 344bff4a4..5fd5359e7 100644 --- a/R/print.R +++ b/R/print.R @@ -49,10 +49,8 @@ print.forecast_binary <- function(x, ...) { } else { cli_text( col_blue( - "Forecast type:" - ) - ) - cli_text( + "Forecast type: " + ), "{forecast_type}" ) } From 8773440cf9fe0214dbc5d6678e1fe3921dcf2d11 Mon Sep 17 00:00:00 2001 From: Nikos Bosse <37978797+nikosbosse@users.noreply.github.com> Date: Mon, 6 May 2024 18:09:26 +0200 Subject: [PATCH 09/10] Applying code suggestions from code review (#806) * correct orcid statements in DESCRIPTION * Automatic readme update [ci skip] * update docs * revert suggested change * update test * make import explicit * update import * delete unnecessary comment --------- Co-authored-by: GitHub Action --- DESCRIPTION | 4 ++-- NAMESPACE | 2 ++ R/check-input-helpers.R | 3 ++- R/check-inputs-scoring-functions.R | 2 +- R/correlations.R | 1 - R/summarise_scores.R | 2 +- README.md | 3 +-- man/scoringutils-package.Rd | 2 +- tests/testthat/test-summarise_scores.R | 8 ++++++++ 9 files changed, 18 insertions(+), 9 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 29ebf9880..f682e1297 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -7,7 +7,7 @@ Authors@R: c( family = "Bosse", role = c("aut", "cre"), email = "nikosbosse@gmail.com", - comment = c(ORCID = "https://orcid.org/0000-0002-7750-5280")), + comment = c(ORCID = "0000-0002-7750-5280")), person(given = "Sam Abbott", role = c("aut"), email = "contact@samabbott.co.uk", @@ -16,7 +16,7 @@ Authors@R: c( family = "Gruson", role = c("aut"), email = "hugo.gruson+R@normalesup.org", - comment = c(ORCID = "https://orcid.org/0000-0002-4094-1476")), + comment = c(ORCID = "0000-0002-4094-1476")), person(given = "Johannes Bracher", role = c("ctb"), email = "johannes.bracher@kit.edu", diff --git a/NAMESPACE b/NAMESPACE index b80e5887e..b8c67e615 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -95,6 +95,7 @@ importFrom(checkmate,assert_factor) importFrom(checkmate,assert_function) importFrom(checkmate,assert_list) importFrom(checkmate,assert_logical) +importFrom(checkmate,assert_matrix) importFrom(checkmate,assert_number) importFrom(checkmate,assert_numeric) importFrom(checkmate,assert_subset) @@ -108,6 +109,7 @@ importFrom(checkmate,check_set_equal) importFrom(checkmate,check_vector) importFrom(checkmate,test_factor) importFrom(checkmate,test_list) +importFrom(checkmate,test_names) importFrom(checkmate,test_numeric) importFrom(checkmate,test_subset) importFrom(cli,cli_abort) diff --git a/R/check-input-helpers.R b/R/check-input-helpers.R index 425f85336..733c7c76b 100644 --- a/R/check-input-helpers.R +++ b/R/check-input-helpers.R @@ -175,7 +175,8 @@ test_columns_present <- function(data, columns) { #' 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 +#' @importFrom checkmate test_names #' @keywords internal_input_check test_columns_not_present <- function(data, columns) { - checkmate::test_names(colnames(data), disjunct.from = columns) + test_names(colnames(data), disjunct.from = columns) } diff --git a/R/check-inputs-scoring-functions.R b/R/check-inputs-scoring-functions.R index 036f34423..8999e28ca 100644 --- a/R/check-inputs-scoring-functions.R +++ b/R/check-inputs-scoring-functions.R @@ -7,7 +7,7 @@ #' N (number of columns) the number of samples per forecast. #' If `observed` is just a single number, then predicted values can just be a #' vector of size N. -#' @importFrom checkmate assert assert_numeric check_matrix +#' @importFrom checkmate assert assert_numeric check_matrix assert_matrix #' @inherit document_assert_functions params return #' @keywords internal_input_check assert_input_sample <- function(observed, predicted) { diff --git a/R/correlations.R b/R/correlations.R index 387ffaa90..9079bf37b 100644 --- a/R/correlations.R +++ b/R/correlations.R @@ -48,7 +48,6 @@ get_correlations <- function(scores, return(correlations[]) } -# define function to obtain upper triangle of matrix get_lower_tri <- function(cormat) { cormat[lower.tri(cormat)] <- NA return(cormat) diff --git a/R/summarise_scores.R b/R/summarise_scores.R index 20e9d073b..29b385aeb 100644 --- a/R/summarise_scores.R +++ b/R/summarise_scores.R @@ -72,7 +72,7 @@ summarise_scores <- function(scores, # if across is provided, calculate new `by` if (!is.null(across)) { - if (by != "model") { + if (!setequal(by, "model")) { warning("You specified `across` and `by` at the same time.", "`by` will be ignored.") } diff --git a/README.md b/README.md index 3c243d777..2e30b9d9f 100644 --- a/README.md +++ b/README.md @@ -104,8 +104,7 @@ forecast_quantile <- example_quantile |> #> unexpected. print(forecast_quantile, 2) -#> Forecast type: -#> quantile +#> Forecast type: quantile #> Forecast unit: #> location, forecast_date, target_end_date, target_type, model, and horizon #> diff --git a/man/scoringutils-package.Rd b/man/scoringutils-package.Rd index 6df7314a3..aab4a6687 100644 --- a/man/scoringutils-package.Rd +++ b/man/scoringutils-package.Rd @@ -24,7 +24,7 @@ Useful links: Authors: \itemize{ \item Sam Abbott \email{contact@samabbott.co.uk} (\href{https://orcid.org/0000-0001-8057-8037}{ORCID}) - \item Hugo Gruson \email{hugo.gruson@lshtm.ac.uk} (\href{https://orcid.org/0000-0002-4094-1476}{ORCID}) + \item Hugo Gruson \email{hugo.gruson+R@normalesup.org} (\href{https://orcid.org/0000-0002-4094-1476}{ORCID}) \item Sebastian Funk \email{sebastian.funk@lshtm.ac.uk} } diff --git a/tests/testthat/test-summarise_scores.R b/tests/testthat/test-summarise_scores.R index 0ac0f58fd..05c92c1d0 100644 --- a/tests/testthat/test-summarise_scores.R +++ b/tests/testthat/test-summarise_scores.R @@ -74,4 +74,12 @@ test_that("summarise_scores() across argument works as expected", { scores, by = c("location", "target_type") ) ) + + expect_warning( + summarise_scores( + scores, across = c("horizon", "model", "forecast_date", "target_end_date"), + by = c("model", "target_type") + ), + "You specified `across` and `by` at the same time.`by` will be ignored" + ) }) From 9d28462c46ea869e0ce17e126c596eed77bbc247 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Sun, 19 May 2024 10:16:01 +0200 Subject: [PATCH 10/10] Accept updated snapshot --- tests/testthat/_snaps/print.md | 60 ++++++++++++---------------------- 1 file changed, 20 insertions(+), 40 deletions(-) diff --git a/tests/testthat/_snaps/print.md b/tests/testthat/_snaps/print.md index 0b0f776eb..9f56ce937 100644 --- a/tests/testthat/_snaps/print.md +++ b/tests/testthat/_snaps/print.md @@ -3,8 +3,7 @@ Code print(dat) Message - Forecast type: - binary + Forecast type: binary Forecast unit: location, location_name, target_end_date, target_type, forecast_date, model, and horizon @@ -42,8 +41,7 @@ Code print(dat) Message - Forecast type: - binary + Forecast type: binary Forecast unit: location, location_name, target_end_date, target_type, forecast_date, model, and horizon @@ -81,8 +79,7 @@ Code print(dat) Message - Forecast type: - binary + Forecast type: binary Forecast unit: location, location_name, target_end_date, target_type, forecast_date, model, and horizon @@ -120,8 +117,7 @@ Code print(dat) Message - Forecast type: - binary + Forecast type: binary Forecast unit: location, location_name, target_end_date, target_type, forecast_date, model, and horizon @@ -159,8 +155,7 @@ Code print(dat) Message - Forecast type: - quantile + Forecast type: quantile Forecast unit: location, target_end_date, target_type, location_name, forecast_date, model, and horizon @@ -199,8 +194,7 @@ Code print(dat) Message - Forecast type: - quantile + Forecast type: quantile Forecast unit: location, target_end_date, target_type, location_name, forecast_date, model, and horizon @@ -239,8 +233,7 @@ Code print(dat) Message - Forecast type: - quantile + Forecast type: quantile Forecast unit: location, target_end_date, target_type, location_name, forecast_date, model, and horizon @@ -279,8 +272,7 @@ Code print(dat) Message - Forecast type: - quantile + Forecast type: quantile Forecast unit: location, target_end_date, target_type, location_name, forecast_date, model, and horizon @@ -319,8 +311,7 @@ Code print(dat) Message - Forecast type: - point + Forecast type: point Forecast unit: location, target_end_date, target_type, location_name, forecast_date, model, and horizon @@ -359,8 +350,7 @@ Code print(dat) Message - Forecast type: - point + Forecast type: point Forecast unit: location, target_end_date, target_type, location_name, forecast_date, model, and horizon @@ -399,8 +389,7 @@ Code print(dat) Message - Forecast type: - point + Forecast type: point Forecast unit: location, target_end_date, target_type, location_name, forecast_date, model, and horizon @@ -439,8 +428,7 @@ Code print(dat) Message - Forecast type: - point + Forecast type: point Forecast unit: location, target_end_date, target_type, location_name, forecast_date, model, and horizon @@ -479,8 +467,7 @@ Code print(dat) Message - Forecast type: - sample + Forecast type: sample Forecast unit: location, location_name, target_end_date, target_type, forecast_date, model, and horizon @@ -518,8 +505,7 @@ Code print(dat) Message - Forecast type: - sample + Forecast type: sample Forecast unit: location, location_name, target_end_date, target_type, forecast_date, model, and horizon @@ -557,8 +543,7 @@ Code print(dat) Message - Forecast type: - sample + Forecast type: sample Forecast unit: location, location_name, target_end_date, target_type, forecast_date, model, and horizon @@ -596,8 +581,7 @@ Code print(dat) Message - Forecast type: - sample + Forecast type: sample Forecast unit: location, location_name, target_end_date, target_type, forecast_date, model, and horizon @@ -635,8 +619,7 @@ Code print(dat) Message - Forecast type: - sample + Forecast type: sample Forecast unit: location, location_name, target_end_date, target_type, forecast_date, model, and horizon @@ -674,8 +657,7 @@ Code print(dat) Message - Forecast type: - sample + Forecast type: sample Forecast unit: location, location_name, target_end_date, target_type, forecast_date, model, and horizon @@ -713,8 +695,7 @@ Code print(dat) Message - Forecast type: - sample + Forecast type: sample Forecast unit: location, location_name, target_end_date, target_type, forecast_date, model, and horizon @@ -752,8 +733,7 @@ Code print(dat) Message - Forecast type: - sample + Forecast type: sample Forecast unit: location, location_name, target_end_date, target_type, forecast_date, model, and horizon