diff --git a/R/check-input-helpers.R b/R/check-input-helpers.R index 7abe0f331..16867581a 100644 --- a/R/check-input-helpers.R +++ b/R/check-input-helpers.R @@ -108,14 +108,3 @@ test_columns_present <- function(data, columns) { return(isTRUE(check)) } -#' Test whether column names are NOT present in a data.frame -#' @description The function checks whether all column names are NOT present. -#' If none of the columns are present, the function returns TRUE. If one or -#' more columns are present, the function returns FALSE. -#' @inheritParams document_check_functions -#' @returns 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) { - test_names(colnames(data), disjunct.from = columns) -} diff --git a/R/class-forecast-binary.R b/R/class-forecast-binary.R index bf4d0b835..ca2b66884 100644 --- a/R/class-forecast-binary.R +++ b/R/class-forecast-binary.R @@ -58,6 +58,7 @@ as_forecast_binary.default <- function(data, #' @export #' @rdname assert_forecast #' @importFrom cli cli_abort +#' @importFrom checkmate test_names #' @keywords validate-forecast-object assert_forecast.forecast_binary <- function( forecast, forecast_type = NULL, verbose = TRUE, ... @@ -65,8 +66,8 @@ assert_forecast.forecast_binary <- function( forecast <- assert_forecast_generic(forecast, verbose) assert_forecast_type(forecast, actual = "binary", desired = forecast_type) - columns_correct <- test_columns_not_present( - forecast, c("sample_id", "quantile_level") + columns_correct <- test_names( + colnames(forecast), disjunct.from = c("sample_id", "quantile_level") ) if (!columns_correct) { #nolint start: keyword_quote_linter diff --git a/man/test_columns_not_present.Rd b/man/test_columns_not_present.Rd deleted file mode 100644 index 5f7b71994..000000000 --- a/man/test_columns_not_present.Rd +++ /dev/null @@ -1,22 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/check-input-helpers.R -\name{test_columns_not_present} -\alias{test_columns_not_present} -\title{Test whether column names are NOT present in a data.frame} -\usage{ -test_columns_not_present(data, columns) -} -\arguments{ -\item{data}{A data.frame or similar to be checked} - -\item{columns}{A character vector of column names to check} -} -\value{ -Returns TRUE if none of the columns are present and FALSE otherwise -} -\description{ -The function checks whether all column names are NOT present. -If none of the columns are present, the function returns TRUE. If one or -more columns are present, the function returns FALSE. -} -\keyword{internal_input_check} diff --git a/tests/testthat/test-check-input-helpers.R b/tests/testthat/test-check-input-helpers.R index 8e9465d35..03aa1185d 100644 --- a/tests/testthat/test-check-input-helpers.R +++ b/tests/testthat/test-check-input-helpers.R @@ -36,15 +36,6 @@ test_that("check_columns_present works", { ) }) -test_that("test_columns_not_present works", { - expect_true( - test_columns_not_present(example_binary, "sample_id") - ) - expect_false( - test_columns_not_present(example_binary, "location") - ) -}) - test_that("check_columns_present() works", { expect_identical( check_columns_present(example_quantile, c("observed", "predicted", "nop")), diff --git a/tests/testthat/test-class-forecast-binary.R b/tests/testthat/test-class-forecast-binary.R index cb95e1d23..681842843 100644 --- a/tests/testthat/test-class-forecast-binary.R +++ b/tests/testthat/test-class-forecast-binary.R @@ -45,6 +45,25 @@ test_that("assert_forecast.forecast_binary works as expected", { ) }) +test_that("assert_forecast.forecast_binary() rejects data with quantile_level column", { + test <- na.omit(as.data.table(example_binary)) + test[, "quantile_level" := 0.5] + expect_error( + as_forecast_binary(test), + "Input looks like a binary forecast, but an additional column" + ) +}) + +test_that("assert_forecast.forecast_binary() accepts valid binary data without sample_id or quantile_level", { + expect_no_error(assert_forecast(example_binary)) +}) + +test_that("test_columns_not_present() is no longer exported or defined", { + expect_false( + exists("test_columns_not_present", + where = asNamespace("scoringutils"), mode = "function") + ) +}) # ==============================================================================