r - R fable::model() “打开”进度条
问题描述
如何“打开”慢速model()
的进度条?根据fable和fabletools的发展,这似乎是一个选项......但我无法打开它。
有人可以告诉我我错过了什么吗?
Sys.setenv(TZ = "Etc/UCT")
library(tidyverse)
library(fable)
#> Loading required package: fabletools
library(tictoc)
getOption("fable.show_progress")
#> [1] TRUE
getOption("fable.progress_bar")
#> NULL
options(fable.progress_bar = TRUE)
# Prepare data
aus <- tsibbledata::hh_budget %>%
filter(Country == "Australia") %>%
select(-Country)
# Create list of all possible combinations
subsets_list <- function(set, subset_size) {
combn(set, subset_size) %>%
BBmisc::convertColsToList() %>%
unname()
}
# All possible aus variable combinations
xregs <-
map(.x = 1:(length(aus) - 2), .f = subsets_list,
set = colnames(aus[3:length(aus)])) %>%
unlist(recursive = F)
# Construct formulas
rhs <- map_chr(seq_along(xregs), ~ paste(xregs[[.]], collapse = " + "))
lhs <- "Debt"
formulas <- map(paste(lhs, rhs, sep = " ~ "), as.formula)
# Create model specifications
model_specs <- set_names(map(formulas, ARIMA), formulas)
# Estimate models
tic()
aus %>%
model(!!!model_specs)
#> # A mable: 1 x 31
#> `Debt ~ DI` `Debt ~ Expenditure`
#> <model> <model>
#> 1 <LM w/ ARIMA(1,1,0) errors> <LM w/ ARIMA(1,1,0) errors>
#> # ... with 29 more variables: `Debt ~ Savings` <model>, `Debt ~
toc()
#> 8.39 sec elapsed
由reprex 包于 2021-01-15 创建(v0.3.0)
解决方案
with_progress()
可以通过使用包中的代码包装您的代码来启用进度条progressr
。进一步的定制也可以从进度包文档中找到:https ://cran.r-project.org/web/packages/progressr/index.html
library(fable)
progressr::with_progress(
tsibbledata::PBS %>%
model(SNAIVE(Cost))
)
推荐阅读
- shell - 在 docker 内运行脚本 shell 不起作用?
- android - 如何解决没有这样的属性:类的 Gradle 版本:jetGradleplugin?
- php - 使用 PHP 和 mySQL 创建出勤表结果
- javascript - 微前端/Web 组件/Vue 路由器错误:未捕获类型错误:无法重新定义属性:$router
- javascript - 对状态变化做出反应动画
- asp.net-core - 如何知道 JsonSerializer.Deserialize 返回的 JSON 类型?
- javascript - 结束函数后停止运行 ElementbyID onClick
- python - 将对象(字符串)转换为 Int32 时出错:TypeError:对象无法转换为 IntegerDtype
- python - 如何使用不同类型的参数列表调用python子进程
- .htaccess - 通过部分修改中间的链接重定向.htaccess