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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

* `parameters()` and the `grid_*()` functions give more information in the error message when non-parameter objects are passed in (#437, #438).

* `encode_unit()` now provides a helpful error when `x` is not a parameter object (#430).

* `value_validate()`, `encode_unit()`, `get_p()`, `get_log_p()`, `get_n()`, `get_n_frac()`, `get_n_frac_range()`, and `get_batch_sizes()` now enforce empty dots (#439).


Expand Down
3 changes: 2 additions & 1 deletion R/encode_unit.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#' @keywords internal
#' @export
encode_unit <- function(x, value, direction, ...) {
arg_match0(direction, values = c("forward", "backward"))
UseMethod("encode_unit")
}

Expand All @@ -29,6 +28,7 @@ encode_unit.default <- function(x, value, direction, ...) {
#' @rdname encode_unit
#' @export
encode_unit.quant_param <- function(x, value, direction, original = TRUE, ...) {
arg_match0(direction, values = c("forward", "backward"))
check_bool(original)
if (has_unknowns(x)) {
cli::cli_abort("The parameter object contains unknowns.")
Expand Down Expand Up @@ -70,6 +70,7 @@ encode_unit.quant_param <- function(x, value, direction, original = TRUE, ...) {
#' @rdname encode_unit
#' @export
encode_unit.qual_param <- function(x, value, direction, ...) {
arg_match0(direction, values = c("forward", "backward"))
check_dots_empty()
if (has_unknowns(x)) {
cli::cli_abort("The parameter object contains unknowns.")
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/_snaps/encode_unit.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@

# bad args

Code
encode_unit("foo")
Condition
Error in `encode_unit()`:
! `x` should be a dials parameter object, not a string.

---

Code
encode_unit(2, prune_method()$values, direction = "forward")
Condition
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-encode_unit.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ test_that("bad args", {
z_0 <- encode_unit(z, prune_method()$values, direction = "forward")
x_0 <- encode_unit(x, 2:7, direction = "forward")

expect_snapshot(
error = TRUE,
encode_unit("foo")
)
expect_snapshot(
error = TRUE,
encode_unit(2, prune_method()$values, direction = "forward")
Expand Down
Loading