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]  
相关推荐
测试界柠檬1 分钟前
面试真题 | web自动化关闭浏览器,quit()和close()的区别
前端·自动化测试·软件测试·功能测试·程序人生·面试·自动化
多多*2 分钟前
OJ在线评测系统 登录页面开发 前端后端联调实现全栈开发
linux·服务器·前端·ubuntu·docker·前端框架
2301_801074152 分钟前
TypeScript异常处理
前端·javascript·typescript
小阿飞_3 分钟前
报错合计-1
前端
caperxi5 分钟前
前端开发中的防抖与节流
前端·javascript·html
霸气小男5 分钟前
react + antDesign封装图片预览组件(支持多张图片)
前端·react.js
susu10830189116 分钟前
前端css样式覆盖
前端·css
学习路上的小刘7 分钟前
vue h5 蓝牙连接 webBluetooth API
前端·javascript·vue.js
&白帝&8 分钟前
vue3常用的组件间通信
前端·javascript·vue.js
小白小白从不日白19 分钟前
react 组件通讯
前端·react.js