Skip to content
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
12 changes: 6 additions & 6 deletions R/aaa_values.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")) {
Expand Down Expand Up @@ -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)) {
Expand All @@ -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)) {
Expand All @@ -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.")
Expand Down
12 changes: 6 additions & 6 deletions R/finalize.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
23 changes: 0 additions & 23 deletions R/misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/_snaps/aaa_values.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
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 <param> object, not the string "not a param".

# value_seq validates inputs

Code
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 <param> object, not the string "not a param".

---

Expand Down Expand Up @@ -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 <param> object, not the string "not a param".

---

Expand Down Expand Up @@ -76,15 +76,15 @@
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 <param> object, not the string "not a param".

# value_inverse validates inputs

Code
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 <param> object, not the string "not a param".

# transforms with unknowns

Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/_snaps/finalize.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,23 @@
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 <param> object, not the string "not a param".

# estimate columns

Code
get_p(1:10)
Condition
Error in `get_p()`:
! `object` must be a single parameter object, not an integer vector.
! `object` must be a <param> object, not an integer vector.

---

Code
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 <param> object, not an integer vector.

---

Expand All @@ -84,15 +84,15 @@
get_n(1:10)
Condition
Error in `get_n()`:
! `object` must be a single parameter object, not an integer vector.
! `object` must be a <param> object, not an integer vector.

---

Code
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 <param> object, not an integer vector.

---

Expand Down