Skip to content

Commit e82ae04

Browse files
committed
Use cli package for class printer
1 parent ddefaee commit e82ae04

10 files changed

+22
-12
lines changed

Diff for: DESCRIPTION

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Depends:
3131
Imports:
3232
bbotk (>= 1.5.0),
3333
checkmate (>= 2.0.0),
34+
cli,
3435
data.table,
3536
lgr,
3637
mlr3misc (>= 0.15.1),

Diff for: NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export(tune)
8383
export(tune_nested)
8484
import(bbotk)
8585
import(checkmate)
86+
import(cli)
8687
import(data.table)
8788
import(mlr3)
8889
import(mlr3misc)

Diff for: R/ArchiveAsyncTuning.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ ArchiveAsyncTuning = R6Class("ArchiveAsyncTuning",
142142
#'
143143
#' @param ... (ignored).
144144
print = function() {
145-
catf("%s with %i evaluations", format(self), self$n_evals)
145+
cat_cli(cli_h1("{format(self)} with {.val {self$n_evals}} evaluations"))
146146
print(as.data.table(self, unnest = NULL, exclude_columns = c(
147147
"x_domain",
148148
"timestamp_xs",

Diff for: R/ArchiveAsyncTuningFrozen.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ ArchiveAsyncTuningFrozen = R6Class("ArchiveAsyncTuningFrozen",
9999
#'
100100
#' @param ... (ignored).
101101
print = function() {
102-
catf("%s with %i evaluations", format(self), self$n_evals)
102+
cat_cli(cli_h1("{.cls {class(self)[1L]}} with {.val {self$n_evals}} evaluations"))
103103
print(as.data.table(self, unnest = NULL, exclude_columns = c(
104104
"x_domain",
105105
"timestamp_xs",

Diff for: R/ArchiveBatchTuning.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ ArchiveBatchTuning = R6Class("ArchiveBatchTuning",
159159
#'
160160
#' @param ... (ignored).
161161
print = function() {
162-
catf("%s with %i evaluations", format(self), self$n_evals)
162+
cat_cli(cli_h1("{.cls {class(self)[1L]}} with {.val {self$n_evals}} evaluations"))
163163
print(as.data.table(self, unnest = NULL, exclude_columns = c("x_domain", "uhash", "timestamp", "runtime_learners", "resample_result")), digits = 2)
164164
print(as.data.table(self, unnest = "x_domain",
165165
exclude_columns = c("uhash", "timestamp", "runtime_learners", "resample_result")),

Diff for: R/AutoTuner.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ AutoTuner = R6Class("AutoTuner",
260260
} else {
261261
self$instance_args$search_space
262262
}
263-
catf("* Search Space:")
263+
cat_cli(cli_li("Search Space:"))
264264
print(as.data.table(search_space)[, c("id", "class", "lower", "upper", "nlevels"), with = FALSE])
265265
},
266266

Diff for: R/Tuner.R

+10-5
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,16 @@ Tuner = R6Class("Tuner",
7070
#'
7171
#' @return (`character()`).
7272
print = function() {
73-
catn(format(self), if (is.na(self$label)) "" else paste0(": ", self$label))
74-
catn(str_indent("* Parameters:", as_short_string(self$param_set$values)))
75-
catn(str_indent("* Parameter classes:", self$param_classes))
76-
catn(str_indent("* Properties:", self$properties))
77-
catn(str_indent("* Packages:", self$packages))
73+
msg_h = if (is.na(self$label)) "" else paste0(": ", self$label)
74+
msg_params = cli_vec(map_chr(self$param_classes, function(p) format_inline('{.cls {p}}')),
75+
style = list(last = ' and ', sep = ', '))
76+
cat_cli({
77+
cli_h1("{.cls {class(self)[1]}}{msg_h}")
78+
cli_li("Parameters: {as_short_string(self$param_set$values)}")
79+
cli_li("Parameter classes: {msg_params}")
80+
cli_li("Properties: {self$properties}")
81+
cli_li("Packages: {.pkg {self$packages}}")
82+
})
7883
},
7984

8085
#' @description

Diff for: R/zzz.R

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#' @import data.table
22
#' @import checkmate
3+
#' @import cli
34
#' @import paradox
45
#' @import mlr3
56
#' @import mlr3misc

Diff for: man/AutoTuner.Rd

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: tests/testthat/_snaps/Tuner.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
Code
44
tuner
55
Output
6-
<Tuner>
6+
7+
-- <Tuner> ---------------------------------------------------------------------
78
* Parameters: p1=TRUE
8-
* Parameter classes: ParamLgl
9+
* Parameter classes: <ParamLgl>
910
* Properties: single-crit
10-
* Packages: mlr3tuning, GenSA
11+
* Packages: mlr3tuning and GenSA
1112

0 commit comments

Comments
 (0)