diff --git a/DESCRIPTION b/DESCRIPTION index c7345338..f682e129 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", @@ -15,8 +15,8 @@ Authors@R: c( person(given = "Hugo", family = "Gruson", role = c("aut"), - email = "hugo.gruson@lshtm.ac.uk", - comment = c(ORCID = "https://orcid.org/0000-0002-4094-1476")), + email = "hugo.gruson+R@normalesup.org", + 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 1c06e843..30f911c7 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -91,6 +91,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) @@ -104,6 +105,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 74b70d55..733c7c76 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 @@ -175,11 +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) { - if (any(columns %in% colnames(data))) { - return(FALSE) - } else { - return(TRUE) - } + test_names(colnames(data), disjunct.from = columns) } diff --git a/R/check-inputs-scoring-functions.R b/R/check-inputs-scoring-functions.R index bb748788..8999e28c 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) { @@ -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)) } diff --git a/R/convenience-functions.R b/R/convenience-functions.R index 56ee1aba..e4f19d3e 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." ) ) diff --git a/R/correlations.R b/R/correlations.R index 6f6cbed8..5d48ed5b 100644 --- a/R/correlations.R +++ b/R/correlations.R @@ -48,7 +48,7 @@ get_correlations <- function(scores, return(correlations[]) } -# helper function to obtain upper triangle of matrix +# helper function to obtain lower triangle of matrix get_lower_tri <- function(cormat) { cormat[lower.tri(cormat)] <- NA return(cormat) diff --git a/R/default-scoring-rules.R b/R/default-scoring-rules.R index b4c2bbca..ec5e6cf5 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. diff --git a/R/print.R b/R/print.R index 344bff4a..5fd5359e 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}" ) } diff --git a/README.md b/README.md index 3c243d77..2e30b9d9 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 6df7314a..aab4a668 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/_snaps/print.md b/tests/testthat/_snaps/print.md index 0b0f776e..9f56ce93 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 diff --git a/tests/testthat/test-summarise_scores.R b/tests/testthat/test-summarise_scores.R index c354d6de..b8c5f23f 100644 --- a/tests/testthat/test-summarise_scores.R +++ b/tests/testthat/test-summarise_scores.R @@ -91,4 +91,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" + ) })