Setters, getters, and validators for parameter ranges.

range_validate(object, range, ukn_ok = TRUE, ..., call = caller_env())

range_get(object, original = TRUE)

range_set(object, range, call = caller_env())

Arguments

object

An object with class quant_param.

range

A two-element numeric vector or list (including Inf). Values can include unknown() when ukn_ok = TRUE.

ukn_ok

A single logical for whether unknown() is an acceptable value.

...

These dots are for future extensions and must be empty.

call

The call passed on to cli::cli_abort().

original

A single logical. Should the range values be in the natural units (TRUE) or in the transformed space (FALSE, if applicable)?

Value

range_validate() returns the new range if it passes the validation process (and throws an error otherwise).

range_get() returns the current range of the object.

range_set() returns an updated version of the parameter object with a new range.

Examples

library(dplyr)

my_lambda <- penalty() |>
  value_set(-4:-1)

try(
  range_validate(my_lambda, c(-10, NA)),
  silent = TRUE
) |>
  print()
#> [1] "Error in eval(expr, envir) : \n  \033[1m\033[22m\033[31m✖\033[39m Value ranges must be non-missing.\n\033[36mℹ\033[39m `Inf` and `unknown()` are acceptable values.\n"
#> attr(,"class")
#> [1] "try-error"
#> attr(,"condition")
#> <error/rlang_error>
#> Error:
#>  Value ranges must be non-missing.
#>  `Inf` and `unknown()` are acceptable values.
#> ---
#> Backtrace:
#>      
#>   1. ├─base::tryCatch(...)
#>   2. └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#>   3. ├─base (local) tryCatchOne(...)
#>   4. │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#>   5. └─base (local) tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
#>   6. └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#>   7. └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#>   8. ├─base::withCallingHandlers(...)
#>   9. ├─base::saveRDS(...)
#>  10. ├─base::do.call(...)
#>  11. ├─base (local) `<fn>`(...)
#>  12. └─global `<fn>`(...)
#>  13.   └─pkgdown::build_site(...)
#>  14.     └─pkgdown:::build_site_local(...)
#>  15.       └─pkgdown::build_reference(...)
#>  16. ─pkgdown:::unwrap_purrr_error(...)
#>  17. └─base::withCallingHandlers(...)
#>  18.         └─purrr::map(...)
#>  19.           └─purrr:::map_("list", .x, .f, ..., .progress = .progress)
#>  20. ─purrr:::with_indexed_errors(...)
#>  21. └─base::withCallingHandlers(...)
#>  22. purrr:::call_with_cleanup(...)
#>  23.             └─pkgdown (local) .f(.x[[i]], ...)
#>  24. base::withCallingHandlers(...)
#>  25.               └─pkgdown:::data_reference_topic(...)
#>  26.                 └─pkgdown:::run_examples(...)
#>  27.                   └─pkgdown:::highlight_examples(code, topic, env = env)
#>  28.                     └─downlit::evaluate_and_highlight(...)
#>  29.                       └─evaluate::evaluate(code, child_env(env), new_device = TRUE, output_handler = output_handler)
#>  30. base::withRestarts(...)
#>  31. └─base (local) withRestartList(expr, restarts)
#>  32. ├─base (local) withOneRestart(withRestartList(expr, restarts[-nr]), restarts[[nr]])
#>  33. │ └─base (local) doWithOneRestart(return(expr), restart)
#>  34. └─base (local) withRestartList(expr, restarts[-nr])
#>  35. └─base (local) withOneRestart(expr, restarts[[1L]])
#>  36. └─base (local) doWithOneRestart(return(expr), restart)
#>  37. evaluate:::with_handlers(...)
#>  38. ├─base::eval(call)
#>  39. │ └─base::eval(call)
#>  40. └─base::withCallingHandlers(...)
#>  41. ─base::withVisible(eval(expr, envir))
#>  42.                         └─base::eval(expr, envir)
#>  43.                           └─base::eval(expr, envir)

range_get(my_lambda)
#> $lower
#> [1] 1e-10
#> 
#> $upper
#> [1] 1
#> 

my_lambda |>
  range_set(c(-10, 2)) |>
  range_get()
#> $lower
#> [1] 1e-10
#> 
#> $upper
#> [1] 100
#>