From 1b8f9e4d4c3ab646739dea9f4c1ce612f8f6da1e Mon Sep 17 00:00:00 2001 From: Hannah Frick Date: Wed, 4 Feb 2026 12:52:26 +0000 Subject: [PATCH] remove `check_param()` in favor of `check_inherits()` --- R/aaa_values.R | 12 ++++++------ R/finalize.R | 12 ++++++------ R/misc.R | 23 ----------------------- tests/testthat/_snaps/aaa_values.md | 10 +++++----- tests/testthat/_snaps/finalize.md | 10 +++++----- 5 files changed, 22 insertions(+), 45 deletions(-) diff --git a/R/aaa_values.R b/R/aaa_values.R index 2462648a..b28811a6 100644 --- a/R/aaa_values.R +++ b/R/aaa_values.R @@ -73,7 +73,7 @@ #' #' @export value_validate <- function(object, values, ..., call = caller_env()) { - check_param(object) + check_inherits(object, "param") res <- switch( object$type, double = , @@ -126,7 +126,7 @@ value_validate_qual <- function(object, values, ..., call = caller_env()) { #' @export #' @rdname value_validate value_seq <- function(object, n, original = TRUE) { - check_param(object) + check_inherits(object, "param") if (inherits(object, "quant_param")) { range_validate(object, object$range, ukn_ok = FALSE) check_number_whole(n, min = 1) @@ -220,7 +220,7 @@ value_seq_qual <- function(object, n) { #' @export #' @rdname value_validate value_sample <- function(object, n, original = TRUE) { - check_param(object) + check_inherits(object, "param") check_number_whole(n, min = 1) check_bool(original) if (inherits(object, "quant_param")) { @@ -343,7 +343,7 @@ value_samp_qual <- function(object, n) { #' @export #' @rdname value_validate value_transform <- function(object, values) { - check_param(object) + check_inherits(object, "param") check_for_unknowns(values) if (is.null(object$trans)) { @@ -363,7 +363,7 @@ trans_wrap <- function(x, object) { #' @export #' @rdname value_validate value_inverse <- function(object, values) { - check_param(object) + check_inherits(object, "param") check_for_unknowns(values) if (is.null(object$trans)) { @@ -384,7 +384,7 @@ inv_wrap <- function(x, object) { #' @export #' @rdname value_validate value_set <- function(object, values) { - check_param(object) + check_inherits(object, "param") check_for_unknowns(values) if (length(values) == 0) { cli::cli_abort("{.arg values} must have at least one element.") diff --git a/R/finalize.R b/R/finalize.R index 7628df5c..4a440412 100644 --- a/R/finalize.R +++ b/R/finalize.R @@ -154,7 +154,7 @@ finalize.default <- function(object, x, force = TRUE, ...) { #' @export #' @rdname finalize get_p <- function(object, x, log_vals = FALSE, ...) { - check_param(object) + check_inherits(object, "param") check_bool(log_vals) rngs <- range_get(object, original = FALSE) @@ -185,14 +185,14 @@ get_p <- function(object, x, log_vals = FALSE, ...) { #' @export #' @rdname finalize get_log_p <- function(object, x, ...) { - check_param(object) + check_inherits(object, "param") get_p(object, x, log_vals = TRUE, ...) } #' @export #' @rdname finalize get_n_frac <- function(object, x, log_vals = FALSE, frac = 1 / 3, ...) { - check_param(object) + check_inherits(object, "param") check_bool(log_vals) check_number_decimal(frac, min = 0, max = 1) @@ -230,7 +230,7 @@ get_n_frac_range <- function( frac = c(1 / 10, 5 / 10), ... ) { - check_param(object) + check_inherits(object, "param") check_bool(log_vals) check_frac_range(frac) @@ -264,14 +264,14 @@ get_n_frac_range <- function( #' @export #' @rdname finalize get_n <- function(object, x, log_vals = FALSE, ...) { - check_param(object) + check_inherits(object, "param") get_n_frac(object, x, log_vals, frac = 1, ...) } #' @export #' @rdname finalize get_rbf_range <- function(object, x, seed = sample.int(10^5, 1), ...) { - check_param(object) + check_inherits(object, "param") rlang::check_installed("kernlab") suppressPackageStartupMessages(requireNamespace("kernlab", quietly = TRUE)) x_mat <- as.matrix(x) diff --git a/R/misc.R b/R/misc.R index e052301a..eb1764b9 100644 --- a/R/misc.R +++ b/R/misc.R @@ -196,29 +196,6 @@ check_inclusive <- function(x, ..., arg = caller_arg(x), call = caller_env()) { invisible(NULL) } -check_param <- function( - x, - ..., - allow_na = FALSE, - allow_null = FALSE, - arg = caller_arg(x), - call = caller_env() -) { - if (!missing(x) && inherits(x, "param")) { - return(invisible(NULL)) - } - - stop_input_type( - x, - c("a single parameter object"), - ..., - allow_na = allow_na, - allow_null = allow_null, - arg = arg, - call = call - ) -} - check_inherits <- function( x, class, diff --git a/tests/testthat/_snaps/aaa_values.md b/tests/testthat/_snaps/aaa_values.md index 7c94649f..fdba0d88 100644 --- a/tests/testthat/_snaps/aaa_values.md +++ b/tests/testthat/_snaps/aaa_values.md @@ -4,7 +4,7 @@ value_validate("not a param", 1) Condition Error in `value_validate()`: - ! `object` must be a single parameter object, not the string "not a param". + ! `object` must be a object, not the string "not a param". # value_seq validates inputs @@ -12,7 +12,7 @@ value_seq("not a param", 5) Condition Error in `value_seq()`: - ! `object` must be a single parameter object, not the string "not a param". + ! `object` must be a object, not the string "not a param". --- @@ -44,7 +44,7 @@ value_sample("not a param", 5) Condition Error in `value_sample()`: - ! `object` must be a single parameter object, not the string "not a param". + ! `object` must be a object, not the string "not a param". --- @@ -76,7 +76,7 @@ value_transform("not a param", 1:3) Condition Error in `value_transform()`: - ! `object` must be a single parameter object, not the string "not a param". + ! `object` must be a object, not the string "not a param". # value_inverse validates inputs @@ -84,7 +84,7 @@ value_inverse("not a param", 1:3) Condition Error in `value_inverse()`: - ! `object` must be a single parameter object, not the string "not a param". + ! `object` must be a object, not the string "not a param". # transforms with unknowns diff --git a/tests/testthat/_snaps/finalize.md b/tests/testthat/_snaps/finalize.md index 63520fb4..dc136e4b 100644 --- a/tests/testthat/_snaps/finalize.md +++ b/tests/testthat/_snaps/finalize.md @@ -52,7 +52,7 @@ get_rbf_range("not a param", mtcars) Condition Error in `get_rbf_range()`: - ! `object` must be a single parameter object, not the string "not a param". + ! `object` must be a object, not the string "not a param". # estimate columns @@ -60,7 +60,7 @@ get_p(1:10) Condition Error in `get_p()`: - ! `object` must be a single parameter object, not an integer vector. + ! `object` must be a object, not an integer vector. --- @@ -68,7 +68,7 @@ get_p(1:10, 1:10) Condition Error in `get_p()`: - ! `object` must be a single parameter object, not an integer vector. + ! `object` must be a object, not an integer vector. --- @@ -84,7 +84,7 @@ get_n(1:10) Condition Error in `get_n()`: - ! `object` must be a single parameter object, not an integer vector. + ! `object` must be a object, not an integer vector. --- @@ -92,7 +92,7 @@ get_n(1:10, 1:10) Condition Error in `get_n()`: - ! `object` must be a single parameter object, not an integer vector. + ! `object` must be a object, not an integer vector. ---