R语言【cli】——可用于进度条格式化字符串的变量

Details

这些变量可以在cli进度条格式字符串中使用。它们是按需计算的。

要在包中使用变量,比如pb_bar,你要么需要从cli中导入pb_bar,要么使用限定格式字符串:cli::pb_bar。

类似地,在R脚本中,您可以在library(cli)之后使用pb_bar,如果不附加cli包,则可以使用cli::pb_bar。

pb_bar

创建可视进度条。如果总单元数未知,则返回空字符串。

R 复制代码
cli_progress_bar(
  total = 100,
  format = "Fitting model {cli::pb_bar} {cli::pb_percent}"
)
复制代码
#> Fitting model ███████████████████████████████   66% 

pb_current

当前进度单元的数量。

R 复制代码
cli_progress_bar(
  total = 100,
  format = "{cli::pb_spin} Reading file {cli::pb_current}/{cli::pb_total}"
)
复制代码
#> ⠙ Reading file 66/100 

pb_current_bytes

格式化为字节的当前进度单元的数目。输出具有六个字符的恒定宽度。

R 复制代码
cli_progress_bar(
  format = "Got {cli::pb_current_bytes} in {cli::pb_elapsed}"
)
复制代码
#> Got 524 kB in 5s

pb_elapsed

进度条开始后经过的时间。时间是在使用cli_progress_bar()或类似方法创建进度条之后测量的。

R 复制代码
cli_progress_bar(
  total = 100,
  format = "{cli::pb_bar} {cli::pb_percent} [{cli::pb_elapsed}]"
)
复制代码
#> ███████████████████████████████   66% [5s]     

pb_elapsed_clock

经过的时间,格式为hh::mm::ss。

R 复制代码
cli_progress_bar(
  total = 100,
  format = "{cli::pb_bar} {cli::pb_percent} [{cli::pb_elapsed_clock}]"
)
复制代码
#> ███████████████████████████████   66% [00:00:05] 

pb_elapsed_raw

进度条开始后的秒数。

R 复制代码
cli_progress_bar(
  total = 100,
  format = "{cli::pb_bar} {cli::pb_percent} [{round(cli::pb_elapsed_raw)}s]"
)
复制代码
#> ███████████████████████████████   66% [5s] 

pb_eta

进度条结束前的估计时间,以人类可读的形式显示。

R 复制代码
cli_progress_bar(
  total = 100,
  format = "{cli::pb_bar} {cli::pb_percent} | ETA: {cli::pb_eta}"
)
复制代码
#> ███████████████████████████████   66% | ETA:  3s   

pb_eta_raw

进度条结束前的估计时间,以秒为单位。如果您想调整默认的pb_eta显示,这很有用。

R 复制代码
cli_progress_bar(
  total = 100,
  format = "{cli::pb_bar} {cli::pb_percent} | ETA: {round(cli::pb_eta_raw)}s"
)
复制代码
#> ███████████████████████████████   66% | ETA: 3s 

pb_eta_str

进度条结束前的估计时间。它包括"ETA:"前缀。只有在时间可以估计的情况下才会显示,否则为空字符串。

R 复制代码
cli_progress_bar(
  total = 100,
  format = "{cli::pb_bar} {cli::pb_percent} | {cli::pb_eta_str}"
)
复制代码
#> ███████████████████████████████   66% | ETA:  3s 

pb_extra

Pb_extra可以用来访问额外的数据,参见cli_progress_bar()和cli_progress_update()的extra参数。

R 复制代码
cli_progress_bar(
  total = 100,
  extra = list(user = whoami::username()),
  format = "Cleaning cache for user '{cli::pb_extra$user}': {cli::pb_current_bytes}"
)
复制代码
#> Cleaning cache for user 'gaborcsardi': 161 MB  

pb_id

R 复制代码
cli_progress_bar(
  format = "Progress bar '{cli::pb_id}' is at {cli::pb_current}"
)
复制代码
#> Progress bar 'cli-82040-1814' is at 64   

pb_name

进度条的名称。这是由开发人员提供的,默认情况下为空字符串。非空名称中添加空格字符。

R 复制代码
cli_progress_bar(
  name = "Loading training data",
  total = 100,
  format = "{cli::pb_name} {cli::pb_bar} {cli::pb_percent}"
)
复制代码
#> Loading training data  ███████████████████████████████   66%    

pb_percent

进度条的百分比,格式总是三个字符加百分号。如果总单位数未知,则为"NA%"。

R 复制代码
cli_progress_bar(
  total = 100,
  format = "{cli::pb_bar} {cli::pb_percent}"
)
复制代码
#> ███████████████████████████████   66%     

pb_pid

进度条的整数进程id。如果您正在聚合来自多个进程的日志输出或进度结果,这将非常有用。

pb_rate

进度速率,以每秒单位数表示,格式为字符串。

R 复制代码
cli_progress_bar(
  total = 156,
  format = "Reading input files {pb_current}/{pb_total} [{pb_rate}]"
)
复制代码
#> Reading input files 68/156 [14/s] 

pb_rate_raw

原始进度速率,单位为每秒的单位数。

R 复制代码
cli_progress_bar(
  total = 156,
  format = "Reading input files {pb_current}/{pb_total} [{round(pb_rate_raw)}/s]"
)
复制代码
#> Reading input files 68/156 [14/s] 

pb_rate_bytes

进度速率,格式为字节每秒,以人类可读的形式。

R 复制代码
cli_progress_bar(
  total = 256 * 1024 * 1014,
  format = paste0(
    "Reading data {pb_current_bytes}/{pb_total_bytes} ",
    "[{ansi_trimws(pb_rate_bytes)}]"
  )
复制代码
#> Reading data  70 MB/266 MB [14 MB/s]  

pb_spin

标记符号。默认的标记符号是通过get_spinner()调用选择的。

R 复制代码
cli_progress_bar(
  total = 100,
  format = "{cli::pb_spin} Reading file {cli::pb_current}/{cli::pb_total}"
)
复制代码
#> ⠙ Reading file 66/100  

pb_status

进度条的状态字符串。默认情况下,这是一个空字符串,但可以在cli_progress_bar()和'cli_progress_update()]中设置它。

pb_timestamp

以ISO 8601格式表示当前时间的时间戳。

R 复制代码
cli_progress_bar(
  "Loading training data files",
  format = "{pb_timestamp} {pb_current} ({pb_rate})"
复制代码
#> 2022-09-07T11:27:50+00:00 125 (25/s) 

pb_total

进度单位的总数,如果单位数量未知,则为NA。

R 复制代码
cli_progress_bar(
  total = 100,
  format = "{cli::pb_spin} Reading file {cli::pb_current}/{cli::pb_total}"
)
复制代码
#> ⠙ Reading file 66/100   

pb_total_bytes

进度单元的总数,格式化为字节,采用人类可读的格式。

R 复制代码
cli_progress_bar(
  total = 256 * 1024 * 1014,
  format = paste0(
    "Reading data {pb_current_bytes}/{pb_total_bytes} ",
    "[{ansi_trimws(pb_rate_bytes)}]"
  )
复制代码
#> Reading data  70 MB/266 MB [14 MB/s]  
相关推荐
GISer_Jing25 分钟前
[总结篇]个人网站
前端·javascript
疯狂的沙粒1 小时前
在web-view 加载的本地及远程HTML中调用uniapp的API及网页和vue页面是如何通讯的?
前端·uni-app·html
小妖6661 小时前
html 滚动条滚动过快会留下边框线
前端·html
heroboyluck1 小时前
Svelte 核心语法详解:Vue/React 开发者如何快速上手?
前端·svelte
海的诗篇_1 小时前
前端开发面试题总结-JavaScript篇(二)
开发语言·前端·javascript·typescript
琹箐1 小时前
ant-design4.xx实现数字输入框; 某些输入法数字需要连续输入两次才显示
前端·javascript·anti-design-vue
程序员-小李1 小时前
VuePress完美整合Toast消息提示
前端·javascript·vue.js
Uyker2 小时前
从零开始制作小程序简单概述
前端·微信小程序·小程序
EndingCoder6 小时前
React从基础入门到高级实战:React 实战项目 - 项目三:实时聊天应用
前端·react.js·架构·前端框架
阿阳微客7 小时前
Steam 搬砖项目深度拆解:从抵触到真香的转型之路
前端·笔记·学习·游戏