Skip to content

Commit

Permalink
use check_param()
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilHvitfeldt committed Dec 1, 2023
1 parent de32db1 commit b275bd1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
4 changes: 1 addition & 3 deletions R/aaa_values.R
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,7 @@ value_set <- function(object, values) {
if (length(values) == 0) {
rlang::abort("`values` should at least one element.")
}
if (!inherits(object, "param")) {
rlang::abort("`object` should be a 'param' object")
}
check_param(object)

if (inherits(object, "quant_param")) {
object <-
Expand Down
9 changes: 3 additions & 6 deletions R/finalize.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,7 @@ finalize.default <- function(object, x, force = TRUE, ...) {
#' @export
#' @rdname finalize
get_p <- function(object, x, log_vals = FALSE, ...) {
if (!inherits(object, "param")) {
rlang::abort("`object` should be a 'param' object.")
}
check_param(object)

rngs <- range_get(object, original = FALSE)
if (!is_unknown(rngs$upper)) {
Expand Down Expand Up @@ -188,9 +186,8 @@ get_log_p <- function(object, x, ...) {
#' @export
#' @rdname finalize
get_n_frac <- function(object, x, log_vals = FALSE, frac = 1/3, ...) {
if (!inherits(object, "param")) {
cli::cli_abort("{.arg object} should be a {.cls param} object.")
}
check_param(object)

rngs <- range_get(object, original = FALSE)
if (!is_unknown(rngs$upper)) {
return(object)
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/_snaps/finalize.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
get_p(1:10)
Condition
Error in `get_p()`:
! `object` should be a 'param' object.
! `object` must be a single parameter object, not an integer vector.

---

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

---

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

---

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

---

Expand Down

0 comments on commit b275bd1

Please sign in to comment.