diff --git a/NAMESPACE b/NAMESPACE
index a9324c67..9e6981d9 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -17,12 +17,15 @@ S3method(grid_latin_hypercube,parameters)
S3method(grid_max_entropy,list)
S3method(grid_max_entropy,param)
S3method(grid_max_entropy,parameters)
+S3method(grid_random,default)
S3method(grid_random,list)
S3method(grid_random,param)
S3method(grid_random,parameters)
+S3method(grid_regular,default)
S3method(grid_regular,list)
S3method(grid_regular,param)
S3method(grid_regular,parameters)
+S3method(grid_space_filling,default)
S3method(grid_space_filling,list)
S3method(grid_space_filling,param)
S3method(grid_space_filling,parameters)
diff --git a/NEWS.md b/NEWS.md
index 06aacf69..aaee8beb 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -6,7 +6,7 @@
* Parameters were added for the `tab_pfn` model: `num_estimators()`, `softmax_temperature()`, `balance_probabilities()`, `average_before_softmax()`, and `training_set_limit()`.
-* `parameters()` and the `grid_*()` functions give more information in the error message when non-parameter objects are passed in (#437).
+* `parameters()` and the `grid_*()` functions give more information in the error message when non-parameter objects are passed in (#437, #438).
# dials 1.4.2
diff --git a/R/grids.R b/R/grids.R
index 052a9c30..477262ea 100644
--- a/R/grids.R
+++ b/R/grids.R
@@ -59,6 +59,24 @@ grid_regular <- function(x, ..., levels = 3, original = TRUE, filter = NULL) {
UseMethod("grid_regular")
}
+#' @export
+#' @rdname grid_regular
+grid_regular.default <- function(
+ x,
+ ...,
+ levels = 3,
+ original = TRUE,
+ filter = NULL
+) {
+ if (missing(x)) {
+ cli::cli_abort("At least one parameter object is required.")
+ }
+ cli::cli_abort(
+ "{.arg x} must be a {.cls param} object, list, or {.cls parameters} object,
+ not {.obj_type_friendly {x}}."
+ )
+}
+
#' @export
#' @rdname grid_regular
grid_regular.parameters <- function(
@@ -239,6 +257,24 @@ grid_random <- function(x, ..., size = 5, original = TRUE, filter = NULL) {
UseMethod("grid_random")
}
+#' @export
+#' @rdname grid_regular
+grid_random.default <- function(
+ x,
+ ...,
+ size = 5,
+ original = TRUE,
+ filter = NULL
+) {
+ if (missing(x)) {
+ cli::cli_abort("At least one parameter object is required.")
+ }
+ cli::cli_abort(
+ "{.arg x} must be a {.cls param} object, list, or {.cls parameters} object,
+ not {.obj_type_friendly {x}}."
+ )
+}
+
#' @export
#' @rdname grid_regular
grid_random.parameters <- function(
diff --git a/R/space_filling.R b/R/space_filling.R
index e5f4a655..badfd5f3 100644
--- a/R/space_filling.R
+++ b/R/space_filling.R
@@ -107,6 +107,24 @@ grid_space_filling <- function(
UseMethod("grid_space_filling")
}
+#' @export
+#' @rdname grid_space_filling
+grid_space_filling.default <- function(
+ x,
+ ...,
+ size = 5,
+ type = "any",
+ original = TRUE
+) {
+ if (missing(x)) {
+ cli::cli_abort("At least one parameter object is required.")
+ }
+ cli::cli_abort(
+ "{.arg x} must be a {.cls param} object, list, or {.cls parameters} object,
+ not {.obj_type_friendly {x}}."
+ )
+}
+
#' @export
#' @rdname grid_space_filling
grid_space_filling.parameters <- function(
diff --git a/man/grid_regular.Rd b/man/grid_regular.Rd
index 97234b4f..054cffc1 100644
--- a/man/grid_regular.Rd
+++ b/man/grid_regular.Rd
@@ -2,10 +2,12 @@
% Please edit documentation in R/grids.R
\name{grid_regular}
\alias{grid_regular}
+\alias{grid_regular.default}
\alias{grid_regular.parameters}
\alias{grid_regular.list}
\alias{grid_regular.param}
\alias{grid_random}
+\alias{grid_random.default}
\alias{grid_random.parameters}
\alias{grid_random.list}
\alias{grid_random.param}
@@ -13,6 +15,8 @@
\usage{
grid_regular(x, ..., levels = 3, original = TRUE, filter = NULL)
+\method{grid_regular}{default}(x, ..., levels = 3, original = TRUE, filter = NULL)
+
\method{grid_regular}{parameters}(x, ..., levels = 3, original = TRUE, filter = NULL)
\method{grid_regular}{list}(x, ..., levels = 3, original = TRUE, filter = NULL)
@@ -21,6 +25,8 @@ grid_regular(x, ..., levels = 3, original = TRUE, filter = NULL)
grid_random(x, ..., size = 5, original = TRUE, filter = NULL)
+\method{grid_random}{default}(x, ..., size = 5, original = TRUE, filter = NULL)
+
\method{grid_random}{parameters}(x, ..., size = 5, original = TRUE, filter = NULL)
\method{grid_random}{list}(x, ..., size = 5, original = TRUE, filter = NULL)
diff --git a/man/grid_space_filling.Rd b/man/grid_space_filling.Rd
index 7571d6d1..b242cd7f 100644
--- a/man/grid_space_filling.Rd
+++ b/man/grid_space_filling.Rd
@@ -2,6 +2,7 @@
% Please edit documentation in R/space_filling.R
\name{grid_space_filling}
\alias{grid_space_filling}
+\alias{grid_space_filling.default}
\alias{grid_space_filling.parameters}
\alias{grid_space_filling.list}
\alias{grid_space_filling.param}
@@ -9,6 +10,8 @@
\usage{
grid_space_filling(x, ..., size = 5, type = "any", original = TRUE)
+\method{grid_space_filling}{default}(x, ..., size = 5, type = "any", original = TRUE)
+
\method{grid_space_filling}{parameters}(
x,
...,
diff --git a/tests/testthat/_snaps/grids.md b/tests/testthat/_snaps/grids.md
index 9ebb1360..570203b8 100644
--- a/tests/testthat/_snaps/grids.md
+++ b/tests/testthat/_snaps/grids.md
@@ -96,8 +96,16 @@
Code
grid_random()
Condition
- Error in `UseMethod()`:
- ! no applicable method for 'grid_random' applied to an object of class "NULL"
+ Error in `grid_random()`:
+ ! At least one parameter object is required.
+
+---
+
+ Code
+ grid_random("not a param")
+ Condition
+ Error in `grid_random()`:
+ ! `x` must be a object, list, or object, not a string.
---
@@ -250,8 +258,16 @@
Code
grid_regular()
Condition
- Error in `UseMethod()`:
- ! no applicable method for 'grid_regular' applied to an object of class "NULL"
+ Error in `grid_regular()`:
+ ! At least one parameter object is required.
+
+---
+
+ Code
+ grid_regular("not a param")
+ Condition
+ Error in `grid_regular()`:
+ ! `x` must be a object, list, or object, not a string.
---
diff --git a/tests/testthat/_snaps/space_filling.md b/tests/testthat/_snaps/space_filling.md
index dca7a9ab..c97ff793 100644
--- a/tests/testthat/_snaps/space_filling.md
+++ b/tests/testthat/_snaps/space_filling.md
@@ -118,8 +118,16 @@
Code
grid_space_filling()
Condition
- Error in `UseMethod()`:
- ! no applicable method for 'grid_space_filling' applied to an object of class "NULL"
+ Error in `grid_space_filling()`:
+ ! At least one parameter object is required.
+
+---
+
+ Code
+ grid_space_filling("not a param")
+ Condition
+ Error in `grid_space_filling()`:
+ ! `x` must be a object, list, or object, not a string.
---
diff --git a/tests/testthat/test-grids.R b/tests/testthat/test-grids.R
index 743a42f8..bfde256a 100644
--- a/tests/testthat/test-grids.R
+++ b/tests/testthat/test-grids.R
@@ -109,8 +109,9 @@ test_that("grid_random validates inputs", {
})
test_that("grid_random() errors with non-param inputs", {
- # no input at all
+ # default method
expect_snapshot(error = TRUE, grid_random())
+ expect_snapshot(error = TRUE, grid_random("not a param"))
# param method
expect_snapshot(error = TRUE, grid_random(penalty(), "min_n"))
@@ -157,8 +158,9 @@ test_that("grid_regular validates inputs", {
})
test_that("grid_regular() errors with non-param inputs", {
- # no input at all
+ # default method
expect_snapshot(error = TRUE, grid_regular())
+ expect_snapshot(error = TRUE, grid_regular("not a param"))
# param method
expect_snapshot(error = TRUE, grid_regular(penalty(), "min_n"))
diff --git a/tests/testthat/test-space_filling.R b/tests/testthat/test-space_filling.R
index c13b6efb..4b2d1146 100644
--- a/tests/testthat/test-space_filling.R
+++ b/tests/testthat/test-space_filling.R
@@ -343,8 +343,9 @@ test_that("grid_space_filling validates inputs", {
})
test_that("grid_space_filling() errors with non-param inputs", {
- # no input at all
+ # default method
expect_snapshot(error = TRUE, grid_space_filling())
+ expect_snapshot(error = TRUE, grid_space_filling("not a param"))
# param method
expect_snapshot(error = TRUE, grid_space_filling(penalty(), "min_n"))