Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

respect inclusive fields in real-valued parameters #347

Open
topepo opened this issue Aug 5, 2024 · 0 comments
Open

respect inclusive fields in real-valued parameters #347

topepo opened this issue Aug 5, 2024 · 0 comments
Labels
bug an unexpected problem or unintended behavior tidy-dev-day 🤓 Tidyverse Developer Day rstd.io/tidy-dev-day

Comments

@topepo
Copy link
Member

topepo commented Aug 5, 2024

Per @simonpcouch's report:

library(dials)
#> Loading required package: scales
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

foo <- function(range = c(0, 1), trans = NULL) {
  dials::new_quant_param(
    type = "double",
    range = range,
    inclusive = c(FALSE, FALSE),
    trans = trans,
    label = c(foo = "bar"),
    finalize = NULL
  )
}

foo() %>% 
  value_seq(10) %>% 
  range()
#> [1] 0 1

# Same is true here but it is difficult to observe due to sampling: 
foo() %>% 
  value_sample(100) %>% 
  range()
#> [1] 0.01505507 0.99933483

Created on 2024-08-05 with reprex v2.1.0

The issue appears to be the use of

seq(from = min(unlist(object$range)), to = max(unlist(object$range)), length.out = n)

We should check the inclusive field and add/subtract .Machine$double.eps (about 2.2e-16) when inclusive = FALSE.

This would affect value_seq_dbl() and value_sample_dbl() and maybe their integer counterparts (with +/- 1L).

@hfrick hfrick added bug an unexpected problem or unintended behavior tidy-dev-day 🤓 Tidyverse Developer Day rstd.io/tidy-dev-day labels Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior tidy-dev-day 🤓 Tidyverse Developer Day rstd.io/tidy-dev-day
Projects
None yet
Development

No branches or pull requests

2 participants