Skip to content

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

Closed

Description

@hfrick

Original title: Consolidate check_list_of_param() and validate_params()

We only really need one function, but we will give it allow_na and allow_unknown arguments. A possible name is check_param_list() as it should operate on the list of param objects.

The grid functions, which currently call validate_params(), need to then collect the dots in a list first but that's not too much overhead and only have to maintain and remember about one checking function.

Activity

  1. hfrick commented on Feb 24, 2026

    @hfrick
    MemberAuthor

    Looking at this from the perspective of the outcome, i.e., the error messages, rather than the code structure. Note that the nice-looking error message in validate_params() about which elements should be param objects never actually fires because it's caught in parameters() first.

    library(dials)
    #> Loading required package: scales
    
    # constructor -----------------------------
    
    # no input
    # should error (for now) but has a cli error that shouldn't show
    parameters() 
    #> Error:
    #> ! ! Could not evaluate cli `{}` expression: `x`.
    #> Caused by error in `eval(expr, envir = envir)`:
    #> ! argument "x" is missing, with no default
    
    # dispatch from param object
    ## should error but doesn't tell you which one is wrong
    parameters(mtry(), "min_n") 
    #> Error in `parameters()`:
    #> ! The objects should all be <param> objects.
    
    # dispatch from list
    ## should error but doesn't tell you which one is wrong
    parameters(list(mtry(), "min_n"))
    #> Error in `parameters()`:
    #> ! The objects should all be <param> objects.
    
    
    # grid functions ----------------------
    
    # should this error or just return an empty tibble? # #428
    # 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 `parameters()`:
    #> ! The objects should all be <param> objects.
    
    # 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 `parameters()`:
    #> ! The objects should all be <param> objects.

    Created on 2026-02-23 with reprex v2.1.1

  2. changed the title [-]Consolidate `check_list_of_param()` and `validate_params()`[/-] [+]Improve checking of parameter inputs to `parameters()` and `grid_*()` functions[/+] on Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions