Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#746 - Reorganise files #940

Merged
merged 11 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 1 addition & 77 deletions R/check-input-helpers.R
Original file line number Diff line number Diff line change
@@ -1,24 +1,4 @@
#' @title Check whether an input is an atomic vector of mode 'numeric'
#'
#' @description Helper function to check whether an input is a numeric vector.
#' @param x input to check
#' @inheritDotParams checkmate::check_numeric
#' @importFrom checkmate check_atomic_vector check_numeric
#' @inherit document_check_functions return
#' @keywords internal_input_check
check_numeric_vector <- function(x, ...) {
# check functions must return TRUE on success
# and a custom error message otherwise
numeric <- check_numeric(x, ...)
vector <- check_atomic_vector(x)
if (!isTRUE(numeric)) {
return(numeric)
} else if (!isTRUE(vector)) {
return(vector)
}
return(TRUE)
}

# to be deleted

#' @title Helper function to convert assert statements into checks
#'
Expand All @@ -40,62 +20,6 @@ check_try <- function(expr) {
return(msg)
}

#' Check that all forecasts have the same number of quantiles or samples
#' @description
#' Function checks the number of quantiles or samples per forecast.
#' If the number of quantiles or samples is the same for all forecasts, it
#' returns TRUE and a string with an error message otherwise.
#' @param forecast_unit Character vector denoting the unit of a single forecast.
#' @importFrom checkmate assert_subset
#' @inherit document_check_functions params return
#' @keywords internal_input_check
check_number_per_forecast <- function(data, forecast_unit) {
# This function doesn't return a forecast object so it's fine to unclass it
# to avoid validation error while subsetting
data <- as.data.table(data)
data <- na.omit(data)
# check whether there are the same number of quantiles, samples --------------
data[, scoringutils_InternalNumCheck := length(predicted), by = forecast_unit]
n <- unique(data$scoringutils_InternalNumCheck)
data[, scoringutils_InternalNumCheck := NULL]
if (length(n) > 1) {
msg <- paste0(
"Some forecasts have different numbers of rows ",
"(e.g. quantiles or samples). ",
"scoringutils found: ", toString(n),
". This may be a problem (it can potentially distort scores, ",
"making it more difficult to compare them), ",
"so make sure this is intended."
)
return(msg)
}
return(TRUE)
}


#' Check that there are no duplicate forecasts
#'
#' @description
#' Runs [get_duplicate_forecasts()] and returns a message if an issue is
#' encountered
#' @inheritParams get_duplicate_forecasts
#' @inherit document_check_functions return
#' @keywords internal_input_check
check_duplicates <- function(data) {
check_duplicates <- get_duplicate_forecasts(data)

if (nrow(check_duplicates) > 0) {
msg <- paste0(
"There are instances with more than one forecast for the same target. ",
"This can't be right and needs to be resolved. Maybe you need to ",
"check the unit of a single forecast and add missing columns? Use ",
"the function get_duplicate_forecasts() to identify duplicate rows"
)
return(msg)
}
return(TRUE)
}


#' Check column names are present in a data.frame
#' @description
Expand Down
Loading