Skip to content

Improve checking of parameter inputs to parameters() and grid_*() functions#437

Merged
hfrick merged 13 commits intomainfrom
check-param-inputs
Apr 8, 2026
Merged

Improve checking of parameter inputs to parameters() and grid_*() functions#437
hfrick merged 13 commits intomainfrom
check-param-inputs

Conversation

@hfrick
Copy link
Copy Markdown
Member

@hfrick hfrick commented Apr 8, 2026

Closes #422

This fixes most of what's laid out in the reprex from the issue (comments still refer to the old behavior). It doesn't add a better error for grid_*.default() since that's a separate issue (#429).

library(dials)
#> Loading required package: scales

# constructor -----------------------------

# no input
# should error (for now) but has a cli error that shouldn't show
parameters() 
#> Error in `parameters()`:
#> ! No input provided. Please supply at least one parameter object.

# dispatch from param object

## should error but doesn't tell you which one is wrong
parameters(mtry(), "min_n") 
#> Error in `parameters()`:
#> ! `Argument 2` must be a <param> object, not the string "min_n".

# dispatch from list

## should error but doesn't tell you which one is wrong
parameters(list(mtry(), "min_n"))
#> Error in `parameters()`:
#> ! `Argument 2` must be a <param> object, not the string "min_n".


# grid functions ----------------------

# should this error or just return an empty tibble?
# if it should error, it needs a better error message
grid_regular() 
#> Error in `UseMethod()`:
#> ! no applicable method for 'grid_regular' applied to an object of class "NULL"

# dispatch from param object

## fires from constructor, 
## thus doesn't tell you which one is wrong *and* 
## has the wrong call
grid_regular(penalty(), "min_n")
#> Error in `grid_regular()`:
#> ! `Argument 2` must be a <param> object without unknowns, not the string "min_n".

# dispatch from list

## fires from constructor, 
## thus doesn't tell you which one is wrong *and* 
## has the wrong call
grid_regular(list(mtry(), "min_n"))
#> Error in `grid_regular()`:
#> ✖ `mtry` must be a <param> object without unknowns.
#> ℹ See the `dials::finalize()` function.

Created on 2026-04-08 with reprex v2.1.1

The formatting of "Argument 2" as code isn't exactly perfect but comes from stop_input_type() which I (currently) don't think is worth taking apart to customize.

I ran revdep checks and it flags tdarec but that's because it's pulling in the unexported check function...

check_param <- getFromNamespace("check_param", "dials")

https://github.com/tdaverse/tdarec/blob/1f60a200f2d67a607ea7c774d62d20ab2ebefef8/R/vpd-summarizers.R#L34

check early for both parameter class and no unknowns so that we get a better error call than via `parameters()` or `validate_params()` from `make_*()`

check that the dots are empty for #434
`validate_params()` can be removed when the user-facing `grid_max_entropy()` and `grid_latin_hypercube()` are removed and `make_max_entropy_grid()` and `make_latin_hypercube_grid()` don't need `validate_params()` anymore
mainly to test for duplicate names again as intended
@hfrick
Copy link
Copy Markdown
Member Author

hfrick commented Apr 8, 2026

Pulling out this commit description for more visibility:
validate_params() can be removed when the user-facing grid_max_entropy() and grid_latin_hypercube() are removed and make_max_entropy_grid() and make_latin_hypercube_grid() don't need validate_params() anymore

@hfrick hfrick merged commit edd71f7 into main Apr 8, 2026
15 checks passed
@hfrick hfrick deleted the check-param-inputs branch April 8, 2026 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve checking of parameter inputs to parameters() and grid_*() functions

1 participant