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

Fix pkgdown #482

Merged
merged 8 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export(crps_sample)
export(dispersion)
export(dss_sample)
export(get_duplicate_forecasts)
export(get_forecast_unit)
export(get_forecast_type)
export(get_forecast_unit)
export(interval_coverage_deviation_quantile)
export(interval_coverage_quantile)
export(interval_coverage_sample)
Expand Down Expand Up @@ -61,6 +61,7 @@ export(plot_ranges)
export(plot_score_table)
export(plot_wis)
export(quantile_score)
export(quantile_to_interval)
export(run_safely)
export(sample_to_quantile)
export(score)
Expand Down
38 changes: 16 additions & 22 deletions R/check-input-helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' @inheritDotParams checkmate::check_numeric
#' @importFrom checkmate check_atomic_vector check_numeric
#' @inherit document_check_functions return
#' @keywords internal
#' @keywords internal_input_check
check_numeric_vector <- function(x, ...) {
# check functions must return TRUE on success
# and a custom error message otherwise
Expand Down Expand Up @@ -36,7 +36,7 @@ check_numeric_vector <- function(x, ...) {
#'
#' @return None. Function errors if quantiles are invalid.
#'
#' @keywords internal
#' @keywords internal_input_check
check_quantiles <- function(quantiles, name = "quantiles", range = c(0, 1)) {
if (any(quantiles < range[1]) || any(quantiles > range[2])) {
stop(name, " must be between ", range[1], " and ", range[2])
Expand All @@ -57,7 +57,7 @@ check_quantiles <- function(quantiles, name = "quantiles", range = c(0, 1)) {
#' @param expr an expression to be evaluated
#' @importFrom checkmate assert assert_numeric check_matrix
#' @inherit document_check_functions return
#' @keywords internal
#' @keywords internal_input_check
check_try <- function(expr) {
result <- try(expr, silent = TRUE)
if (is.null(result)) {
Expand All @@ -79,7 +79,7 @@ check_try <- function(expr) {
#' @return The function returns `NULL`, but throws an error if the variable is
#' missing.
#'
#' @keywords internal
#' @keywords internal_input_check
assert_not_null <- function(...) {
vars <- list(...)
varnames <- names(vars)
Expand Down Expand Up @@ -112,7 +112,7 @@ assert_not_null <- function(...) {
#' within another checking function.
#' @inherit document_assert_functions return
#'
#' @keywords internal
#' @keywords internal_input_check
assert_equal_length <- function(...,
one_allowed = TRUE,
call_levels_up = 2) {
Expand Down Expand Up @@ -161,7 +161,7 @@ assert_equal_length <- function(...,
#' @param attribute The name of the attribute to check
#' @param expected The expected value of the attribute
#' @inherit document_check_functions return
#' @keywords internal
#' @keywords internal_input_check
check_attribute_conflict <- function(object, attribute, expected) {
existing <- attr(object, attribute)
if (is.vector(existing) && is.vector(expected)) {
Expand All @@ -188,8 +188,9 @@ check_attribute_conflict <- function(object, attribute, expected) {
#' @description
#' Check whether the data.table has a column called `model`.
#' If not, a column called `model` is added with the value `Unspecified model`.
#' @inheritParams score
#' @return The data.table with a column called `model`
#' @keywords internal
#' @keywords internal_input_check
assure_model_column <- function(data) {
if (!("model" %in% colnames(data))) {
message(
Expand All @@ -208,7 +209,7 @@ assure_model_column <- function(data) {
#' returns TRUE and a string with an error message otherwise.
#' @param forecast_unit Character vector denoting the unit of a single forecast.
#' @inherit document_check_functions params return
#' @keywords internal
#' @keywords internal_input_check
check_number_per_forecast <- function(data, forecast_unit) {
# check whether there are the same number of quantiles, samples --------------
data[, scoringutils_InternalNumCheck := length(predicted), by = forecast_unit]
Expand All @@ -235,7 +236,7 @@ check_number_per_forecast <- function(data, forecast_unit) {
#' an error message, otherwise it returns TRUE.
#' @inherit document_check_functions params return
#'
#' @keywords internal
#' @keywords internal_input_check
check_no_NA_present <- function(data, columns) {
for (x in columns){
if (anyNA(data[[x]])) {
Expand All @@ -253,20 +254,13 @@ check_no_NA_present <- function(data, columns) {
}




# print stuff
diagnose <- function(data) {

}

#' 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
#' @keywords internal_input_check
check_duplicates <- function(data, forecast_unit = NULL) {
check_duplicates <- get_duplicate_forecasts(data, forecast_unit = forecast_unit)

Expand All @@ -290,7 +284,7 @@ check_duplicates <- function(data, forecast_unit = NULL) {
#' and returns a message with the first issue encountered.
#' @inherit document_check_functions params return
#' @importFrom checkmate assert_character
#' @keywords check-inputs
#' @keywords internal_input_check
check_columns_present <- function(data, columns) {
if (is.null(columns)) {
return(TRUE)
Expand Down Expand Up @@ -322,7 +316,7 @@ check_columns_present <- function(data, columns) {
#' are present, the function returns TRUE.
#' @inheritParams document_check_functions
#' @return Returns TRUE if all columns are present and FALSE otherwise
#' @keywords internal
#' @keywords internal_input_check
test_columns_present <- function(data, columns) {
check <- check_columns_present(data, columns)
return(is.logical(check))
Expand All @@ -334,7 +328,7 @@ 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
#' @keywords internal
#' @keywords internal_input_check
test_columns_not_present <- function(data, columns) {
if (any(columns %in% colnames(data))) {
return(FALSE)
Expand All @@ -349,7 +343,7 @@ test_columns_not_present <- function(data, columns) {
#' "quantile" and "sample_id" is present.
#' @inherit document_check_functions params return
#' @importFrom checkmate check_data_frame
#' @keywords check-inputs
#' @keywords internal_input_check
check_data_columns <- function(data) {
is_data <- check_data_frame(data, min.rows = 1)
if (!is.logical(is_data)) {
Expand All @@ -374,7 +368,7 @@ check_data_columns <- function(data) {
#' @param object An object to be checked
#' @param attribute name of an attribute to be checked
#' @inherit document_check_functions return
#' @keywords check-inputs
#' @keywords internal_input_check
check_has_attribute <- function(object, attribute) {
if (is.null(attr(object, attribute))) {
return(
Expand Down
24 changes: 12 additions & 12 deletions R/check-inputs-scoring-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#' vector of size N.
#' @importFrom checkmate assert assert_numeric check_matrix
#' @inherit document_assert_functions return
#' @keywords check-inputs
#' @keywords internal_input_check
assert_input_sample <- function(observed, predicted) {
assert_numeric(observed, min.len = 1)
n_obs <- length(observed)
Expand All @@ -30,7 +30,7 @@ assert_input_sample <- function(observed, predicted) {
#' @title Check that inputs are correct for sample-based forecast
#' @inherit assert_input_sample params description
#' @inherit document_check_functions return
#' @keywords check-inputs
#' @keywords internal_input_check
check_input_sample <- function(observed, predicted) {
result <- check_try(assert_input_sample(observed, predicted))
return(result)
Expand All @@ -54,7 +54,7 @@ check_input_sample <- function(observed, predicted) {
#' FALSE. Whether the quantile levels are required to be unique or not.
#' @importFrom checkmate assert assert_numeric check_matrix check_vector
#' @inherit document_assert_functions return
#' @keywords internal
#' @keywords internal_input_check
assert_input_quantile <- function(observed, predicted, quantile,
unique_quantiles = TRUE) {
assert_numeric(observed, min.len = 1)
Expand Down Expand Up @@ -85,7 +85,7 @@ assert_input_quantile <- function(observed, predicted, quantile,
#' @title Check that inputs are correct for quantile-based forecast
#' @inherit assert_input_quantile params description
#' @inherit check_input_sample return description
#' @keywords check-inputs
#' @keywords internal_input_check
check_input_quantile <- function(observed, predicted, quantile) {
result <- check_try(assert_input_quantile(observed, predicted, quantile))
return(result)
Expand All @@ -106,7 +106,7 @@ check_input_quantile <- function(observed, predicted, quantile) {
#' (25%, 75%) prediction interval.
#' @importFrom rlang warn
#' @inherit document_assert_functions return
#' @keywords internal
#' @keywords internal_input_check
assert_input_interval <- function(observed, lower, upper, range) {

assert(check_numeric_vector(observed, min.len = 1))
Expand Down Expand Up @@ -145,7 +145,7 @@ assert_input_interval <- function(observed, lower, upper, range) {
#' @title Check that inputs are correct for interval-based forecast
#' @inherit assert_input_interval params description
#' @inherit check_input_sample return description
#' @keywords check-inputs
#' @keywords internal_input_check
check_input_interval <- function(observed, lower, upper, range) {
result <- check_try(assert_input_quantile(observed, lower, upper, range))
return(result)
Expand All @@ -167,7 +167,7 @@ check_input_interval <- function(observed, lower, upper, range) {
#' available factor level.
#' @importFrom checkmate assert assert_factor
#' @inherit document_assert_functions return
#' @keywords check-inputs
#' @keywords internal_input_check
assert_input_binary <- function(observed, predicted) {
assert_factor(observed, n.levels = 2, min.len = 1)
assert_numeric(predicted, lower = 0, upper = 1)
Expand All @@ -179,7 +179,7 @@ assert_input_binary <- function(observed, predicted) {
#' @title Check that inputs are correct for binary forecast
#' @inherit assert_input_binary params description
#' @inherit document_check_functions return
#' @keywords check-inputs
#' @keywords internal_input_check
check_input_binary <- function(observed, predicted) {
result <- check_try(assert_input_binary(observed, predicted))
return(result)
Expand All @@ -194,7 +194,7 @@ check_input_binary <- function(observed, predicted) {
#' @param predicted Input to be checked. Should be a numeric vector with the
#' predicted values of size n
#' @inherit document_assert_functions return
#' @keywords check-inputs
#' @keywords internal_input_check
assert_input_point <- function(observed, predicted) {
assert(check_numeric(observed))
assert(check_numeric(predicted))
Expand All @@ -205,7 +205,7 @@ assert_input_point <- function(observed, predicted) {
#' @title Check that inputs are correct for point forecast
#' @inherit assert_input_point params description
#' @inherit document_check_functions return
#' @keywords check-inputs
#' @keywords internal_input_check
check_input_point <- function(observed, predicted) {
result <- check_try(assert_input_point(observed, predicted))
return(result)
Expand All @@ -224,7 +224,7 @@ check_input_point <- function(observed, predicted) {
#' @inherit assert_input_binary
#' @inherit document_assert_functions return
#' @importFrom checkmate assert_vector check_matrix check_vector assert
#' @keywords check-inputs
#' @keywords internal_input_check
assert_dims_ok_point <- function(observed, predicted) {
assert_vector(observed, min.len = 1)
n_obs <- length(observed)
Expand All @@ -250,7 +250,7 @@ assert_dims_ok_point <- function(observed, predicted) {
#' @title Check Inputs Have Matching Dimensions
#' @inherit assert_dims_ok_point params description
#' @inherit document_check_functions return
#' @keywords check-inputs
#' @keywords internal_input_check
check_dims_ok_point <- function(observed, predicted) {
result <- check_try(assert_dims_ok_point(observed, predicted))
return(result)
Expand Down
4 changes: 4 additions & 0 deletions R/documentation-templates.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,26 @@
#' @return Returns TRUE if the check was successful and a string with an
#' error message otherwise
#' @name document_check_functions
#' @keywords internal
NULL

#' Documentation template for check functions
#' @returns Returns NULL invisibly if the assertion was successful and throws an
#' error otherwise.
#' @name document_assert_functions
#' @keywords internal
NULL

#' Documentation template for test functions
#' @returns Returns TRUE if the check was successful and FALSE otherwise
#' @name document_test_functions
#' @keywords internal
NULL

#' Documentation template for scoring input data
#' @param data A data frame (or similar) of forecasts following the
#' specifications detailed in [score()].
#' @param scores A data.table of scores as produced by [score()].
#' @name document_score_data
#' @keywords internal
NULL
23 changes: 8 additions & 15 deletions R/get_-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#' @return Character vector of length one with either "binary", "quantile",
#' "sample" or "point".
#' @export
#' @keywords check-forceasts
#' @keywords check-forecasts
get_forecast_type <- function(data) {
assert_data_frame(data)
assert(check_columns_present(data, c("observed", "predicted")))
Expand Down Expand Up @@ -50,7 +50,7 @@ get_forecast_type <- function(data) {
#' @inheritParams document_check_functions
#' @importFrom checkmate test_factor test_numeric
#' @return Returns TRUE if basic requirements are satisfied and FALSE otherwise
#' @keywords internal
#' @keywords internal_input_check
test_forecast_type_is_binary <- function(data) {
observed_correct <- test_factor(x = data$observed)
predicted_correct <- test_numeric(x = data$predicted)
Expand All @@ -61,7 +61,7 @@ test_forecast_type_is_binary <- function(data) {
#' @description Checks type of the necessary columns.
#' @inheritParams document_check_functions
#' @return Returns TRUE if basic requirements are satisfied and FALSE otherwise
#' @keywords internal
#' @keywords internal_input_check
test_forecast_type_is_sample <- function(data) {
observed_correct <- test_numeric(x = data$observed)
predicted_correct <- test_numeric(x = data$predicted)
Expand All @@ -73,7 +73,7 @@ test_forecast_type_is_sample <- function(data) {
#' @description Checks type of the necessary columns.
#' @inheritParams document_check_functions
#' @return Returns TRUE if basic requirements are satisfied and FALSE otherwise
#' @keywords internal
#' @keywords internal_input_check
test_forecast_type_is_point <- function(data) {
observed_correct <- test_numeric(x = data$observed)
predicted_correct <- test_numeric(x = data$predicted)
Expand All @@ -85,7 +85,7 @@ test_forecast_type_is_point <- function(data) {
#' @description Checks type of the necessary columns.
#' @inheritParams document_check_functions
#' @return Returns TRUE if basic requirements are satisfied and FALSE otherwise
#' @keywords internal
#' @keywords internal_input_check
test_forecast_type_is_quantile <- function(data) {
observed_correct <- test_numeric(x = data$observed)
predicted_correct <- test_numeric(x = data$predicted)
Expand All @@ -100,13 +100,10 @@ test_forecast_type_is_quantile <- function(data) {
#' of observed or predicted values). The function checks whether the input is
#' a factor, or else whether it is integer (or can be coerced to integer) or
#' whether it's continuous.
#'
#' @param x Input used to get the type.
#'
#' @return Character vector of length one with either "classification",
#' "integer", or "continuous"
#'
#' @keywords internal
#' @keywords internal_input_check
get_type <- function(x) {
if (is.factor(x)) {
return("classification")
Expand All @@ -129,15 +126,11 @@ get_type <- function(x) {


#' @title Get metrics that were used for scoring
#'
#' @description Internal helper function to get the metrics that were used
#' to score forecasts.
#' @param score A data.table with an attribute `metric_names`
#'
#' @param scores A data.table with an attribute `metric_names`
#' @return Character vector with the metrics that were used for scoring.
#'
#' @keywords internal

#' @keywords internal_input_check
get_metrics <- function(scores) {
metric_names <- attr(scores, "metric_names")
if (is.null(metric_names)) {
Expand Down
Loading
Loading