Skip to content

Commit 44ba2aa

Browse files
authored
Merge pull request #427 from tidymodels/remove-check_param
remove `check_param()` in favor of `check_inherits()`
2 parents 6b29cb9 + 1b8f9e4 commit 44ba2aa

File tree

5 files changed

+22
-45
lines changed

5 files changed

+22
-45
lines changed

R/aaa_values.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
#'
7474
#' @export
7575
value_validate <- function(object, values, ..., call = caller_env()) {
76-
check_param(object)
76+
check_inherits(object, "param")
7777
res <- switch(
7878
object$type,
7979
double = ,
@@ -126,7 +126,7 @@ value_validate_qual <- function(object, values, ..., call = caller_env()) {
126126
#' @export
127127
#' @rdname value_validate
128128
value_seq <- function(object, n, original = TRUE) {
129-
check_param(object)
129+
check_inherits(object, "param")
130130
if (inherits(object, "quant_param")) {
131131
range_validate(object, object$range, ukn_ok = FALSE)
132132
check_number_whole(n, min = 1)
@@ -220,7 +220,7 @@ value_seq_qual <- function(object, n) {
220220
#' @export
221221
#' @rdname value_validate
222222
value_sample <- function(object, n, original = TRUE) {
223-
check_param(object)
223+
check_inherits(object, "param")
224224
check_number_whole(n, min = 1)
225225
check_bool(original)
226226
if (inherits(object, "quant_param")) {
@@ -343,7 +343,7 @@ value_samp_qual <- function(object, n) {
343343
#' @export
344344
#' @rdname value_validate
345345
value_transform <- function(object, values) {
346-
check_param(object)
346+
check_inherits(object, "param")
347347
check_for_unknowns(values)
348348

349349
if (is.null(object$trans)) {
@@ -363,7 +363,7 @@ trans_wrap <- function(x, object) {
363363
#' @export
364364
#' @rdname value_validate
365365
value_inverse <- function(object, values) {
366-
check_param(object)
366+
check_inherits(object, "param")
367367
check_for_unknowns(values)
368368

369369
if (is.null(object$trans)) {
@@ -384,7 +384,7 @@ inv_wrap <- function(x, object) {
384384
#' @export
385385
#' @rdname value_validate
386386
value_set <- function(object, values) {
387-
check_param(object)
387+
check_inherits(object, "param")
388388
check_for_unknowns(values)
389389
if (length(values) == 0) {
390390
cli::cli_abort("{.arg values} must have at least one element.")

R/finalize.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ finalize.default <- function(object, x, force = TRUE, ...) {
154154
#' @export
155155
#' @rdname finalize
156156
get_p <- function(object, x, log_vals = FALSE, ...) {
157-
check_param(object)
157+
check_inherits(object, "param")
158158
check_bool(log_vals)
159159

160160
rngs <- range_get(object, original = FALSE)
@@ -185,14 +185,14 @@ get_p <- function(object, x, log_vals = FALSE, ...) {
185185
#' @export
186186
#' @rdname finalize
187187
get_log_p <- function(object, x, ...) {
188-
check_param(object)
188+
check_inherits(object, "param")
189189
get_p(object, x, log_vals = TRUE, ...)
190190
}
191191

192192
#' @export
193193
#' @rdname finalize
194194
get_n_frac <- function(object, x, log_vals = FALSE, frac = 1 / 3, ...) {
195-
check_param(object)
195+
check_inherits(object, "param")
196196
check_bool(log_vals)
197197
check_number_decimal(frac, min = 0, max = 1)
198198

@@ -230,7 +230,7 @@ get_n_frac_range <- function(
230230
frac = c(1 / 10, 5 / 10),
231231
...
232232
) {
233-
check_param(object)
233+
check_inherits(object, "param")
234234
check_bool(log_vals)
235235
check_frac_range(frac)
236236

@@ -264,14 +264,14 @@ get_n_frac_range <- function(
264264
#' @export
265265
#' @rdname finalize
266266
get_n <- function(object, x, log_vals = FALSE, ...) {
267-
check_param(object)
267+
check_inherits(object, "param")
268268
get_n_frac(object, x, log_vals, frac = 1, ...)
269269
}
270270

271271
#' @export
272272
#' @rdname finalize
273273
get_rbf_range <- function(object, x, seed = sample.int(10^5, 1), ...) {
274-
check_param(object)
274+
check_inherits(object, "param")
275275
rlang::check_installed("kernlab")
276276
suppressPackageStartupMessages(requireNamespace("kernlab", quietly = TRUE))
277277
x_mat <- as.matrix(x)

R/misc.R

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -196,29 +196,6 @@ check_inclusive <- function(x, ..., arg = caller_arg(x), call = caller_env()) {
196196
invisible(NULL)
197197
}
198198

199-
check_param <- function(
200-
x,
201-
...,
202-
allow_na = FALSE,
203-
allow_null = FALSE,
204-
arg = caller_arg(x),
205-
call = caller_env()
206-
) {
207-
if (!missing(x) && inherits(x, "param")) {
208-
return(invisible(NULL))
209-
}
210-
211-
stop_input_type(
212-
x,
213-
c("a single parameter object"),
214-
...,
215-
allow_na = allow_na,
216-
allow_null = allow_null,
217-
arg = arg,
218-
call = call
219-
)
220-
}
221-
222199
check_inherits <- function(
223200
x,
224201
class,

tests/testthat/_snaps/aaa_values.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
value_validate("not a param", 1)
55
Condition
66
Error in `value_validate()`:
7-
! `object` must be a single parameter object, not the string "not a param".
7+
! `object` must be a <param> object, not the string "not a param".
88

99
# value_seq validates inputs
1010

1111
Code
1212
value_seq("not a param", 5)
1313
Condition
1414
Error in `value_seq()`:
15-
! `object` must be a single parameter object, not the string "not a param".
15+
! `object` must be a <param> object, not the string "not a param".
1616

1717
---
1818

@@ -44,7 +44,7 @@
4444
value_sample("not a param", 5)
4545
Condition
4646
Error in `value_sample()`:
47-
! `object` must be a single parameter object, not the string "not a param".
47+
! `object` must be a <param> object, not the string "not a param".
4848

4949
---
5050

@@ -76,15 +76,15 @@
7676
value_transform("not a param", 1:3)
7777
Condition
7878
Error in `value_transform()`:
79-
! `object` must be a single parameter object, not the string "not a param".
79+
! `object` must be a <param> object, not the string "not a param".
8080

8181
# value_inverse validates inputs
8282

8383
Code
8484
value_inverse("not a param", 1:3)
8585
Condition
8686
Error in `value_inverse()`:
87-
! `object` must be a single parameter object, not the string "not a param".
87+
! `object` must be a <param> object, not the string "not a param".
8888

8989
# transforms with unknowns
9090

tests/testthat/_snaps/finalize.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,23 @@
5252
get_rbf_range("not a param", mtcars)
5353
Condition
5454
Error in `get_rbf_range()`:
55-
! `object` must be a single parameter object, not the string "not a param".
55+
! `object` must be a <param> object, not the string "not a param".
5656

5757
# estimate columns
5858

5959
Code
6060
get_p(1:10)
6161
Condition
6262
Error in `get_p()`:
63-
! `object` must be a single parameter object, not an integer vector.
63+
! `object` must be a <param> object, not an integer vector.
6464

6565
---
6666

6767
Code
6868
get_p(1:10, 1:10)
6969
Condition
7070
Error in `get_p()`:
71-
! `object` must be a single parameter object, not an integer vector.
71+
! `object` must be a <param> object, not an integer vector.
7272

7373
---
7474

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

8989
---
9090

9191
Code
9292
get_n(1:10, 1:10)
9393
Condition
9494
Error in `get_n()`:
95-
! `object` must be a single parameter object, not an integer vector.
95+
! `object` must be a <param> object, not an integer vector.
9696

9797
---
9898

0 commit comments

Comments
 (0)