Skip to content

Commit

Permalink
add input checks to sample_to_quantile()
Browse files Browse the repository at this point in the history
  • Loading branch information
nikosbosse committed Mar 28, 2024
1 parent 2eee97a commit f70bf30
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions R/utils_data_handling.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ merge_pred_and_obs <- function(forecasts, observations,
#' @importFrom data.table as.data.table
#' @importFrom stats quantile
#' @importFrom methods hasArg
#' @importFrom checkmate assert_numeric
#' @keywords data-handling
#' @export
#' @examples
Expand All @@ -105,6 +106,7 @@ sample_to_quantile <- function(data,
quantile_level = c(0.05, 0.25, 0.5, 0.75, 0.95),
type = 7) {
data <- ensure_data.table(data)
assert_numeric(quantile_level, min.len = 1)
reserved_columns <- c("predicted", "sample_id")
by <- setdiff(colnames(data), reserved_columns)

Expand Down Expand Up @@ -135,11 +137,10 @@ sample_to_quantile <- function(data,
#' @param keep_range_col Logical, default is `FALSE`. Keep the
#' interval_range and boundary columns after transformation?
#' @return a data.table in a plain quantile format
#' @importFrom data.table copy
#' @keywords internal
interval_long_to_quantile <- function(data,
keep_range_col = FALSE) {
data <- data.table::as.data.table(data)
data <- ensure_data.table(data)

# filter out duplicated median
# note that this also filters out instances where range is NA, i.e.
Expand Down Expand Up @@ -290,7 +291,7 @@ sample_to_interval_long <- function(data,
interval_range = c(0, 50, 90),
type = 7,
keep_quantile_col = TRUE) {
data <- data.table::as.data.table(data)
data <- ensure_data.table(data)

lower_quantiles <- (100 - interval_range) / 200
upper_quantiles <- 1 - lower_quantiles
Expand Down

0 comments on commit f70bf30

Please sign in to comment.