Skip to content

refactor print.numeric_range() #83

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

Merged
merged 1 commit into from
May 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 11 additions & 19 deletions R/adjust-numeric-range.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,20 @@ adjust_numeric_range <- function(x, lower_limit = -Inf, upper_limit = Inf) {
#' @export
print.numeric_range <- function(x, ...) {
trn <- ifelse(x$trained, " [trained]", "")
# todo could be na
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically this works as if, since signif(NA) = NA. it will thus show up as NA in the print method.

If we want it to show missing that would't be hard to change

if (!is_tune(x$arguments$lower_limit)) {
if (!is_tune(x$arguments$upper_limit)) {
rng_txt <-
paste0(
"between [",
signif(x$arguments$lower_limit, 3),
", ",
signif(x$arguments$upper_limit, 3),
"]"
)
} else {
rng_txt <- paste0("between [", signif(x$arguments$lower_limit, 3), ", ?]")
}

if (is_tune(x$arguments$lower_limit)) {
lower_limit <- "?"
} else {
lower_limit <- signif(x$arguments$lower_limit, 3)
}
if (is_tune(x$arguments$upper_limit)) {
upper_limit <- "?"
} else {
if (!is_tune(x$arguments$upper_limit)) {
rng_txt <- paste0("between [?, ", signif(x$arguments$upper_limit, 3), "]")
} else {
rng_txt <- "between [?, ?]"
}
upper_limit <- signif(x$arguments$upper_limit, 3)
}

rng_txt <- paste0("between [", lower_limit, ", ", upper_limit, "]")

cli::cli_bullets(c(
"*" = "Constrain numeric predictions to be {rng_txt}{trn}."
))
Expand Down