tidymodels / dials

Tools for creating tuning parameter values
https://dials.tidymodels.org/
Other
111 stars 26 forks source link

Opaque error from `parameters()` with `new_*_param(..., label = NULL)` #349

Open owenjonesuob opened 2 weeks ago

owenjonesuob commented 2 weeks ago

We can specify a new parameter with new_quant_param() or new_qual_param().

The docs state that label is an optional parameter:

https://github.com/tidymodels/dials/blob/210055fa7f4e9483567fbf3bd642c31b5116608e/R/constructors.R#L34-L36

But if no label is specified, we get an opaque error when handing our new parameter to parameters():

library(dials)
#> Loading required package: scales

with_label <- function() new_quant_param(
  values = 1,
  label = c("with_label" = "Here is a label")
)

sans_label <- function() new_quant_param(
  values = 1
)

parameters(with_label())
#> Collection of 1 parameters for tuning
#> 
#>  identifier       type    object
#>  with_label with_label nparam[+]

parameters(sans_label())
#> Error in `purrr::map_chr()`:
#> ℹ In index: 1.
#> Caused by error:
#> ! Result must be length 1, not 0.

Created on 2024-09-02 with reprex v2.1.1

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.3.2 (2023-10-31) #> os Amazon Linux 2023.5.20240708 #> system x86_64, linux-gnu #> ui X11 #> language (EN) #> collate C.UTF-8 #> ctype C.UTF-8 #> tz Europe/London #> date 2024-09-02 #> pandoc 3.1.11 @ /usr/lib/rstudio-server/bin/quarto/bin/tools/x86_64/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> cli 3.6.3 2024-06-21 [1] CRAN (R 4.3.2) #> colorspace 2.1-1 2024-07-26 [2] CRAN (R 4.3.2) #> dials * 1.3.0 2024-07-30 [2] CRAN (R 4.3.2) #> DiceDesign 1.10 2023-12-07 [2] CRAN (R 4.3.2) #> digest 0.6.36 2024-06-23 [2] CRAN (R 4.3.2) #> dplyr 1.1.4 2023-11-17 [2] CRAN (R 4.3.2) #> evaluate 0.24.0 2024-06-10 [2] CRAN (R 4.3.2) #> fansi 1.0.6 2023-12-08 [2] CRAN (R 4.3.2) #> fastmap 1.2.0 2024-05-15 [2] CRAN (R 4.3.2) #> fs 1.6.4 2024-04-25 [2] CRAN (R 4.3.2) #> generics 0.1.3 2022-07-05 [2] CRAN (R 4.3.2) #> glue 1.7.0 2024-01-09 [2] CRAN (R 4.3.2) #> hardhat 1.4.0 2024-06-02 [2] CRAN (R 4.3.2) #> htmltools 0.5.8.1 2024-04-04 [2] CRAN (R 4.3.2) #> knitr 1.48 2024-07-07 [2] CRAN (R 4.3.2) #> lifecycle 1.0.4 2023-11-07 [2] CRAN (R 4.3.2) #> magrittr 2.0.3 2022-03-30 [2] CRAN (R 4.3.2) #> munsell 0.5.1 2024-04-01 [2] CRAN (R 4.3.2) #> pillar 1.9.0 2023-03-22 [2] CRAN (R 4.3.2) #> pkgconfig 2.0.3 2019-09-22 [2] CRAN (R 4.3.2) #> purrr 1.0.2 2023-08-10 [2] CRAN (R 4.3.2) #> R6 2.5.1 2021-08-19 [2] CRAN (R 4.3.2) #> reprex 2.1.1 2024-07-06 [2] CRAN (R 4.3.2) #> rlang 1.1.4 2024-06-04 [2] CRAN (R 4.3.2) #> rmarkdown 2.27 2024-05-17 [2] CRAN (R 4.3.2) #> rstudioapi 0.16.0 2024-03-24 [2] CRAN (R 4.3.2) #> scales * 1.3.0 2023-11-28 [2] CRAN (R 4.3.2) #> sessioninfo 1.2.2 2021-12-06 [2] CRAN (R 4.3.2) #> tibble 3.2.1 2023-03-20 [2] CRAN (R 4.3.2) #> tidyselect 1.2.1 2024-03-11 [2] CRAN (R 4.3.2) #> utf8 1.2.4 2023-10-22 [2] CRAN (R 4.3.2) #> vctrs 0.6.5 2023-12-01 [2] CRAN (R 4.3.2) #> withr 3.0.1 2024-07-31 [2] CRAN (R 4.3.2) #> xfun 0.46 2024-07-18 [2] CRAN (R 4.3.2) #> yaml 2.3.10 2024-07-26 [2] CRAN (R 4.3.2) #> #> [1] /home/owen10004/efs/R/x86_64-amazon-linux-gnu-library/4.3 #> [2] /usr/lib64/R/site-library #> [3] /usr/lib64/R/library #> #> ────────────────────────────────────────────────────────────────────────────── ```

It's because the label is used within parameters() to construct the parameter names:

https://github.com/tidymodels/dials/blob/210055fa7f4e9483567fbf3bd642c31b5116608e/R/parameters.R#L39