Skip to content

Commit

Permalink
Use cli package for class printer
Browse files Browse the repository at this point in the history
  • Loading branch information
lona-k committed Jan 12, 2025
1 parent ddefaee commit e82ae04
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 12 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Depends:
Imports:
bbotk (>= 1.5.0),
checkmate (>= 2.0.0),
cli,
data.table,
lgr,
mlr3misc (>= 0.15.1),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export(tune)
export(tune_nested)
import(bbotk)
import(checkmate)
import(cli)
import(data.table)
import(mlr3)
import(mlr3misc)
Expand Down
2 changes: 1 addition & 1 deletion R/ArchiveAsyncTuning.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ ArchiveAsyncTuning = R6Class("ArchiveAsyncTuning",
#'
#' @param ... (ignored).
print = function() {
catf("%s with %i evaluations", format(self), self$n_evals)
cat_cli(cli_h1("{format(self)} with {.val {self$n_evals}} evaluations"))
print(as.data.table(self, unnest = NULL, exclude_columns = c(
"x_domain",
"timestamp_xs",
Expand Down
2 changes: 1 addition & 1 deletion R/ArchiveAsyncTuningFrozen.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ ArchiveAsyncTuningFrozen = R6Class("ArchiveAsyncTuningFrozen",
#'
#' @param ... (ignored).
print = function() {
catf("%s with %i evaluations", format(self), self$n_evals)
cat_cli(cli_h1("{.cls {class(self)[1L]}} with {.val {self$n_evals}} evaluations"))
print(as.data.table(self, unnest = NULL, exclude_columns = c(
"x_domain",
"timestamp_xs",
Expand Down
2 changes: 1 addition & 1 deletion R/ArchiveBatchTuning.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ ArchiveBatchTuning = R6Class("ArchiveBatchTuning",
#'
#' @param ... (ignored).
print = function() {
catf("%s with %i evaluations", format(self), self$n_evals)
cat_cli(cli_h1("{.cls {class(self)[1L]}} with {.val {self$n_evals}} evaluations"))
print(as.data.table(self, unnest = NULL, exclude_columns = c("x_domain", "uhash", "timestamp", "runtime_learners", "resample_result")), digits = 2)
print(as.data.table(self, unnest = "x_domain",
exclude_columns = c("uhash", "timestamp", "runtime_learners", "resample_result")),
Expand Down
2 changes: 1 addition & 1 deletion R/AutoTuner.R
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ AutoTuner = R6Class("AutoTuner",
} else {
self$instance_args$search_space
}
catf("* Search Space:")
cat_cli(cli_li("Search Space:"))
print(as.data.table(search_space)[, c("id", "class", "lower", "upper", "nlevels"), with = FALSE])
},

Expand Down
15 changes: 10 additions & 5 deletions R/Tuner.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,16 @@ Tuner = R6Class("Tuner",
#'
#' @return (`character()`).
print = function() {
catn(format(self), if (is.na(self$label)) "" else paste0(": ", self$label))
catn(str_indent("* Parameters:", as_short_string(self$param_set$values)))
catn(str_indent("* Parameter classes:", self$param_classes))
catn(str_indent("* Properties:", self$properties))
catn(str_indent("* Packages:", self$packages))
msg_h = if (is.na(self$label)) "" else paste0(": ", self$label)
msg_params = cli_vec(map_chr(self$param_classes, function(p) format_inline('{.cls {p}}')),
style = list(last = ' and ', sep = ', '))
cat_cli({
cli_h1("{.cls {class(self)[1]}}{msg_h}")
cli_li("Parameters: {as_short_string(self$param_set$values)}")
cli_li("Parameter classes: {msg_params}")
cli_li("Properties: {self$properties}")
cli_li("Packages: {.pkg {self$packages}}")
})
},

#' @description
Expand Down
1 change: 1 addition & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#' @import data.table
#' @import checkmate
#' @import cli
#' @import paradox
#' @import mlr3
#' @import mlr3misc
Expand Down
1 change: 1 addition & 0 deletions man/AutoTuner.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions tests/testthat/_snaps/Tuner.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
Code
tuner
Output
<Tuner>
-- <Tuner> ---------------------------------------------------------------------
* Parameters: p1=TRUE
* Parameter classes: ParamLgl
* Parameter classes: <ParamLgl>
* Properties: single-crit
* Packages: mlr3tuning, GenSA
* Packages: mlr3tuning and GenSA

0 comments on commit e82ae04

Please sign in to comment.