为什么 CLI 消息的顺序与 R 中的代码不同

问题描述 投票:0回答:1

在使用

cli
包打印命令行消息时,我遇到了相当奇怪的行为。请参阅下面的简单示例:

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...")
  
}

运行此功能时,

test_cli_orders()

我希望

cli_text
的文本出现在最后一个
cli_progress_step
的“2 已完成”之后,但它会产生:

enter image description here

很混乱,经过多次实验也不知道是什么原因造成的。我非常感谢您的想法。

r command-line-interface
1个回答
1
投票

这是因为你最后的

cli_text
被认为是之前的
cli_progress
的进步。您可以在打印文本之前通过
cli_progress_done
结束它。

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()

RESULTS

© www.soinside.com 2019 - 2024. All rights reserved.