Skip to content

Commit

Permalink
Remove sprintf and add cli inline markup.
Browse files Browse the repository at this point in the history
  • Loading branch information
lona-k committed Dec 20, 2024
1 parent 9024161 commit 268eab7
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 30 deletions.
4 changes: 2 additions & 2 deletions R/Graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ Graph = R6Class("Graph",
scc = self$edges[, list(sccssors = paste(unique(dst_id), collapse = ",")), by = list(ID = src_id)]
lines = scc[prd[lines, on = "ID"], on = "ID"][, c("ID", "State", "sccssors", "prdcssors")]
lines[is.na(lines)] = ""
cli_h1(sprintf("Graph with %s PipeOps:", nrow(lines)))
cli_h1("Graph with {nrow(lines)} PipeOps:")
## limit column width ##

outwidth = getOption("width") %??% 80 # output width we want (default 80)
Expand All @@ -430,7 +430,7 @@ Graph = R6Class("Graph",
ppunit = "<SUPPRESSED>"
}
pp = paste0(c("<INPUT>", ppunit, "<OUTPUT>"), collapse = " -> ")
cli_h3(sprintf("Pipeline: %s", pp))
cli_h3("Pipeline: {.strong {pp}}")
} else {
cat("Empty Graph.\n")
}
Expand Down
2 changes: 1 addition & 1 deletion R/GraphLearner.R
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ GraphLearner = R6Class("GraphLearner", inherit = Learner,
ppunit = "<SUPPRESSED>"
}
pp = paste0(c("<INPUT>", ppunit, "<OUTPUT>"), collapse = " -> ")
cli_h3(sprintf("Pipeline: %s", pp))
cli_h3("Pipeline: {.strong {pp}}")
}
),
active = list(
Expand Down
9 changes: 5 additions & 4 deletions R/PipeOp.R
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,12 @@ PipeOp = R6Class("PipeOp",
}
}

cli_h1(sprintf("PipeOp %s: %strained", self$id, if (self$is_trained) "" else "not "))
cli_text(sprintf("values: %s", as_short_string(self$param_set$values)))
cli_h3("Input channels:")
msg_h = if (self$is_trained) "" else "not "
cli_h1("PipeOp {self$id}: {msg_h}trained")
cli_text("values: {.arg {as_short_string(self$param_set$values)}}")
cli_h3("{.strong Input channels:}")
type_table_printout(self$input)
cli_h3("Output channels:")
cli_h3("{.strong Output channels:}")
type_table_printout(self$output)
},

Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/_snaps/PipeOp.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Message
-- PipeOp nop: not trained -----------------------------------------------------
values: list()
values: `list()`
-- Input channels:
Output
Expand All @@ -27,7 +27,7 @@
Message
-- PipeOp debug.multi: not trained ---------------------------------------------
values: list()
values: `list()`
-- Input channels:
Output
Expand All @@ -54,7 +54,7 @@
Message
-- PipeOp debug.multi: not trained ---------------------------------------------
values: list()
values: `list()`
-- Input channels:
Output
Expand All @@ -81,7 +81,7 @@
Message
-- PipeOp branch: not trained --------------------------------------------------
values: selection=odin
values: `selection=odin`
-- Input channels:
Output
Expand All @@ -105,7 +105,7 @@
Message
-- PipeOp classif.debug: not trained -------------------------------------------
values: list()
values: `list()`
-- Input channels:
Output
Expand Down
18 changes: 0 additions & 18 deletions tests/testthat/test_PipeOp.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,6 @@ test_that("PipeOp printer", {
expect_snapshot(print(PipeOpDebugMulti$new(100, 0)))
expect_snapshot(print(PipeOpBranch$new(c("odin", "dva", "tri"))))
expect_snapshot(print(PipeOpLearner$new(mlr_learners$get("classif.debug"))))


# expect_output(print(PipeOpNOP$new()),
# "PipeOp.*<nop>.*not trained.*values.*list().*Input channels.*input \\[\\*,\\*\\]\n.*Output channels.*output \\[\\*,\\*\\]$")
#
#
# expect_output(print(PipeOpDebugMulti$new(3, 4)),
# "PipeOp.*<debug.multi>.*not trained.*values.*list().*Input channels.*input_1 \\[\\*,\\*\\], input_2 \\[\\*,\\*\\], input_3 \\[\\*,\\*\\]\n.*Output channels.*output_1 \\[\\*,\\*\\], output_2 \\[\\*,\\*\\], output_3 \\[\\*,\\*\\], output_4 \\[\\*,\\*\\]$")
#
#
# expect_output(print(PipeOpDebugMulti$new(100, 0)),
# "\\[\\.\\.\\. \\([0-9]+ lines omitted\\)\\]")
#
# expect_output(print(PipeOpBranch$new(c("odin", "dva", "tri"))),
# "Output channels.*odin \\[\\*,\\*\\], dva \\[\\*,\\*\\], tri \\[\\*,\\*\\]$")
#
# expect_output(print(PipeOpLearner$new(mlr_learners$get("classif.debug"))),
# "PipeOp.*<classif.debug>.*Input channels.*input \\[TaskClassif,TaskClassif\\]\nOutput channels.*output \\[NULL,PredictionClassif\\]$")
})

test_that("Prevent creation of PipeOps with no channels", {
Expand Down

0 comments on commit 268eab7

Please sign in to comment.