I have come across rather weird behavior when using the cli
package to print Command Line messages. Please see the simple example below:
library(cli)
test_cli_orders <- function() {
Sys.sleep(1)
cli_progress_step(msg = "Doing 1", msg_done = "1 is done")
Sys.sleep(1)
cli_progress_step(msg = "Doing 2", msg_done = "2 is done")
Sys.sleep(1)
cli_text("I should be displayed last...")
}
When running this function,
test_cli_orders()
I'd expect the text of cli_text
to appear after "2 is done" from the last cli_progress_step
, but it yields:
It is very confusing, and I have no idea what caused it after many experiments. I'd greatly appreciate your thoughts.
This is because your cli_text
at the end is considered as a progress of previous cli_progress
. You can end it by cli_progress_done
before printing your text.
library(cli)
test_cli_orders <- function() {
Sys.sleep(1)
cli_progress_step(msg = "doing 1", msg_done = "1 is done")
Sys.sleep(1)
cli_progress_step(msg = "Doing 2", msg_done = "2 is done")
Sys.sleep(1)
cli_progress_done()
cli_text("I should be displayed last...")
}
test_cli_orders()