R寓言::model() "turn on"进度条

标签 r r6 fable-r

如何“打开”速度较慢的 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 package 于 2021 年 1 月 15 日创建(v0.3.0)

最佳答案

可以通过使用 progressr 包中的 with_progress() 包装代码来启用进度条。还可以从 Progressr 包文档中找到进一步的自定义:https://cran.r-project.org/web/packages/progressr/index.html

library(fable)
progressr::with_progress(
  tsibbledata::PBS %>% 
    model(SNAIVE(Cost))
)

关于R寓言::model() "turn on"进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65741603/

相关文章:

r - 如何记录 R6 类的 S3 泛型?

R:如何为R6类定义多个构造函数?

r - 寓言包 ARIMA 算法是否能够并行工作?

forecasting - 我是否需要使用 future_map 或 map 来并行化寓言预测?

r - 使用 R 中另一个列表的所有可能组合创建列表

r - 计算 R 中向量的所有子集

r - 提取数据框中每个元素的前n个值的索引

r - 如何在 R 中创建具有不相等组的因子变量?得到警告

r - 为不在包中的 R6 类创建 Rd 文档文件