tidyverts / fable

Tidy time series forecasting
https://fable.tidyverts.org
GNU General Public License v3.0
564 stars 66 forks source link

Error when running example from Readme #142

Closed jgjl closed 5 years ago

jgjl commented 5 years ago

Hi,

I just installed fable and ran the example from the Readme in a new R session. I get the following error:

 library(fable)
Loading required package: fablelite
> library(tsibble)
> library(tsibbledata)
> library(lubridate)
Attaching package: ‘lubridate’
The following objects are masked from ‘package:tsibble’:
    interval, new_interval
The following object is masked from ‘package:base’:
    date
> library(dplyr)
Attaching package: ‘dplyr’
The following objects are masked from ‘package:lubridate’:
    intersect, setdiff, union
The following object is masked from ‘package:tsibble’:
    id
The following objects are masked from ‘package:stats’:
    filter, lag
The following objects are masked from ‘package:base’:
    intersect, setdiff, setequal, union
> aus_retail %>%
+     filter(
+         State %in% c("New South Wales", "Victoria"),
+         Industry == "Department stores"
+     ) %>% 
+     model(
+         ets = ETS(box_cox(Turnover, 0.3)),
+         arima = ARIMA(log(Turnover)),
+         snaive = SNAIVE(Turnover)
+     ) %>%
+     forecast %>% 
+     autoplot(filter(aus_retail, year(Month) > 2010), level = NULL)
Error: Column `ets` must be length 2 (the number of rows) or one, not 0
In addition: Warning message:
.key is deprecated 

Is this expected to happen?

mitchelloharawild commented 5 years ago

Seems to work fine for me. Do you have the latest versions of fable, fablelite and tsibble?

library(fable)
#> Loading required package: fablelite
library(tsibble)
library(tsibbledata)
library(lubridate)
#> 
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:tsibble':
#> 
#>     interval, new_interval
#> The following object is masked from 'package:base':
#> 
#>     date
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:lubridate':
#> 
#>     intersect, setdiff, union
#> The following object is masked from 'package:tsibble':
#> 
#>     id
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
aus_retail %>%
  filter(
    State %in% c("New South Wales", "Victoria"),
    Industry == "Department stores"
  ) %>% 
  model(
    ets = ETS(box_cox(Turnover, 0.3)),
    arima = ARIMA(log(Turnover)),
    snaive = SNAIVE(Turnover)
  ) %>%
  forecast %>% 
  autoplot(filter(aus_retail, year(Month) > 2010), level = NULL)

Created on 2019-05-05 by the reprex package (v0.2.1)

jgjl commented 5 years ago

Thank you for the quick feedback!

I just reinstalled everything from Github on my Debian machine, yet I still get the same error. When I run the example on my Macbook Pro, it works though. Seems to be an issue of in my setup on the Debian Machine.

Sorry for the noise.

mitchelloharawild commented 5 years ago

Odd, I'm running on debian. Do you have could you post your sessionInfo()?

jgjl commented 5 years ago

Ok, I deleted everything related to R and installed all packages from the source based on r-base-dev 3.6. Now the example works on Debian Stretch as it should.

jgjl commented 5 years ago

Here we go again, the problem re-appeared:

sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 9 (stretch)

Matrix products: default
BLAS:   /usr/lib/openblas-base/libblas.so.3
LAPACK: /usr/lib/libopenblasp-r0.2.19.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8   
 [6] LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] tsibbledata_0.0.0.9000 tsibble_0.8.0          fable_0.0.0.9100       fablelite_0.0.0.9100   ggrepel_0.8.0.9000     gridExtra_2.3         
 [7] checkmate_1.9.3        ggforce_0.2.2          broom_0.5.2            sitools_1.4            here_0.1               lubridate_1.7.4       
[13] iptools_0.6.1          forcats_0.4.0          stringr_1.4.0          dplyr_0.8.0.1          purrr_0.3.2            readr_1.3.1           
[19] tidyr_0.8.3.9000       tibble_2.1.1           ggplot2_3.1.1          tidyverse_1.2.1        scales_1.0.0           plyr_1.8.4            
[25] sets_1.0-18            glue_1.3.1            

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.1           lattice_0.20-38      assertthat_0.2.1     zeallot_0.1.0        rprojroot_1.3-2      R6_2.4.0             cellranger_1.1.0    
 [8] backports_1.1.4      httr_1.4.0           pillar_1.3.1         tictoc_1.0           rlang_0.3.4.9003     lazyeval_0.2.2       readxl_1.3.1        
[15] rstudioapi_0.10      AsioHeaders_1.12.1-1 polyclip_1.10-0      triebeard_0.3.0      munsell_0.5.0        compiler_3.6.0       numDeriv_2016.8-1   
[22] modelr_0.1.4         pkgconfig_2.0.2      tidyselect_0.2.5     RClickhouse_0.4.0    crayon_1.3.4         dbplyr_1.4.0         withr_2.1.2         
[29] MASS_7.3-51.3        grid_3.6.0           nlme_3.1-139         jsonlite_1.6         gtable_0.3.0         DBI_1.0.0            magrittr_1.5        
[36] cli_1.1.0            stringi_1.4.3        farver_1.1.0         xml2_1.2.0           generics_0.0.2       vctrs_0.1.0.9003     tools_3.6.0         
[43] tweenr_1.0.1         hms_0.4.2            yaml_2.2.0           colorspace_1.4-1     rvest_0.3.3          haven_2.1.0         

The error:

> aus_retail %>%
+     filter(
+         State %in% c("New South Wales", "Victoria"),
+         Industry == "Department stores"
+     ) %>% 
+     model(
+         ets = ETS(box_cox(Turnover, 0.3)),
+         arima = ARIMA(log(Turnover)),
+         snaive = SNAIVE(Turnover)
+     ) %>%
+     forecast %>% 
+     autoplot(filter(aus_retail, year(Month) > 2010), level = NULL)
Error: Column `ets` must be length 2 (the number of rows) or one, not 0
In addition: Warning message:
.key is deprecated 

Traceback:

> traceback()
22: stop(list(message = "Column `ets` must be length 2 (the number of rows) or one, not 0", 
        call = NULL, cppstack = NULL))
21: mutate_impl(.data, dots, caller_env())
20: mutate.tbl_df(.data, !!!dots)
19: mutate(.data, !!!dots)
18: transmute.default(., !!!keys, !!!fits)
17: transmute(., !!!keys, !!!fits)
16: function_list[[i]](value)
15: freduce(value, `_function_list`)
14: `_fseq`(`_lhs`)
13: eval(quote(`_fseq`(`_lhs`)), env, env)
12: eval(quote(`_fseq`(`_lhs`)), env, env)
11: withVisible(eval(quote(`_fseq`(`_lhs`)), env, env))
10: .data %>% transmute(!!!keys, !!!fits) %>% as_mable(keys, names(fits))
9: model.tbl_ts(., ets = ETS(box_cox(Turnover, 0.3)), arima = ARIMA(log(Turnover)), 
       snaive = SNAIVE(Turnover))
8: model(., ets = ETS(box_cox(Turnover, 0.3)), arima = ARIMA(log(Turnover)), 
       snaive = SNAIVE(Turnover))
7: function_list[[i]](value)
6: freduce(value, `_function_list`)
5: `_fseq`(`_lhs`)
4: eval(quote(`_fseq`(`_lhs`)), env, env)
3: eval(quote(`_fseq`(`_lhs`)), env, env)
2: withVisible(eval(quote(`_fseq`(`_lhs`)), env, env))
1: aus_retail %>% filter(State %in% c("New South Wales", "Victoria"), 
       Industry == "Department stores") %>% model(ets = ETS(box_cox(Turnover, 
       0.3)), arima = ARIMA(log(Turnover)), snaive = SNAIVE(Turnover)) %>% 
       forecast %>% autoplot(filter(aus_retail, year(Month) > 2010), 
       level = NULL)
mitchelloharawild commented 5 years ago

Odd, I'm unable to reproduce this issue. My best guess is that this is because you are using the development version of tidyr. There are some substantial changes being made in that package, many that (perhaps unintentionally) break the functionality of the current CRAN version. fable currently is set to work with the latest version of its CRAN dependencies.

library(fable)
#> Loading required package: fablelite
library(tsibble)
library(tsibbledata)
library(lubridate)
#> 
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:tsibble':
#> 
#>     interval, new_interval
#> The following object is masked from 'package:base':
#> 
#>     date
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:lubridate':
#> 
#>     intersect, setdiff, union
#> The following object is masked from 'package:tsibble':
#> 
#>     id
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
aus_retail %>%
  filter(
    State %in% c("New South Wales", "Victoria"),
    Industry == "Department stores"
  ) %>% 
  model(
    ets = ETS(box_cox(Turnover, 0.3)),
    arima = ARIMA(log(Turnover)),
    snaive = SNAIVE(Turnover)
  ) %>%
  forecast %>% 
  autoplot(filter(aus_retail, year(Month) > 2010), level = NULL)


sessionInfo()
#> R version 3.5.3 (2019-03-11)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 18.04.2 LTS
#> 
#> Matrix products: default
#> BLAS: /usr/local/lib/R/lib/libRblas.so
#> LAPACK: /usr/local/lib/R/lib/libRlapack.so
#> 
#> locale:
#>  [1] LC_CTYPE=en_AU.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_AU.UTF-8        LC_COLLATE=en_AU.UTF-8    
#>  [5] LC_MONETARY=en_AU.UTF-8    LC_MESSAGES=en_AU.UTF-8   
#>  [7] LC_PAPER=en_AU.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C       
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] dplyr_0.8.1            lubridate_1.7.4        tsibbledata_0.0.0.9000
#> [4] tsibble_0.8.0          fable_0.0.0.9100       fablelite_0.0.0.9100  
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_1.0.1        urca_1.3-0        pillar_1.4.0     
#>  [4] compiler_3.5.3    highr_0.8         plyr_1.8.4       
#>  [7] tools_3.5.3       digest_0.6.18     lattice_0.20-38  
#> [10] nlme_3.1-137      evaluate_0.13     tibble_2.1.1     
#> [13] gtable_0.3.0      pkgconfig_2.0.2   rlang_0.3.4      
#> [16] yaml_2.2.0        xfun_0.6          stringr_1.4.0    
#> [19] knitr_1.22        generics_0.0.2    feasts_0.0.0.9001
#> [22] grid_3.5.3        tidyselect_0.2.5  glue_1.3.1       
#> [25] R6_2.4.0          rmarkdown_1.10.16 tidyr_0.8.3      
#> [28] purrr_0.3.2       ggplot2_3.1.1     magrittr_1.5     
#> [31] scales_1.0.0      htmltools_0.3.6   assertthat_0.2.1 
#> [34] colorspace_1.4-1  numDeriv_2016.8-1 labeling_0.3     
#> [37] stringi_1.4.3     lazyeval_0.2.2    munsell_0.5.0    
#> [40] crayon_1.3.4

Created on 2019-05-17 by the reprex package (v0.2.1)

jgjl commented 5 years ago

Yes, thank you!

I completely missed that I installed the dev version of tidyr. With the CRAN version the example works. This also explains why it worked a few days ago but now the error came back.