Search code examples
rr6fable-r

R fable::model() "turn on" progress bar


How do I "turn on" the progress bar for slower model()s? It seems to be an option according to development in fable and fabletools... but I can't turn it on.

Can someone please tell me what I am missing?

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

Created on 2021-01-15 by the reprex package (v0.3.0)


Solution

  • Progress bars can be enabled by wrapping your code with with_progress() from the progressr package. Further customisation can also be found from the progressr package documentation: https://cran.r-project.org/web/packages/progressr/index.html

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