autolayer() error help

Hi, I would like some advice on a persistent error using forecast::autolayer(). The error is:

Error: Invalid input: date_trans works with object class Date only...

This error happens with a rmarkdown script with the following set up

MyDeleteItems<-ls()
rm(list=MyDeleteItems)
knitr::opts_knit$set(root.dir='~/Dropbox/Teaching/TSFE/FIN7028')
knitr::opts_chunk$set(echo = FALSE,cache=TRUE,warning = FALSE, message = FALSE)
library(fpp2)
library(knitr)
library(kableExtra)
library(tidyr)
library(dplyr)
load("data/fin7028_dat.RData")
all<-ls()
keep<-c('vix_ts','r2000r_m_ts',"indices_m","ftse_m_ts","next_m_tr_ts","next_m_tr")
rm(list=setdiff(all,keep)) 

The code that throws the error is

fit1 <- auto.arima(ftse_m_ts, d=0, xreg=trend)
fit2 <- auto.arima(ftse_m_ts,d=1)
fc1 <- forecast(fit1, xreg=length(ftse_m_ts) + 1:10)
fc2 <- forecast(fit2, h=10)
autoplot(ftse_m_ts) +
  autolayer(fc2)
  autolayer(fc1)

I have tried to unload ggfortify using unloadNamespace("ggfortify") as I have read that this package does not play nice with forecast but still get the above error.

Any help or guidance is much appreciated.

Here is my session info

R version 3.6.0 (2019-04-26)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.5

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

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

other attached packages:
 [1] kableExtra_1.1.0  knitr_1.27        fpp2_2.3          expsmooth_2.3     fma_2.4          
 [6] forecast_8.11     fable_0.1.2       feasts_0.1.2      fabletools_0.1.2  tsibbledata_0.1.0
[11] tsibble_0.8.6     ggplot2_3.2.1     lubridate_1.7.4   tidyr_1.0.2       dplyr_0.8.3      
[16] tibble_2.1.3      fpp3_0.1         

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.3        lattice_0.20-38   zoo_1.8-7         assertthat_0.2.1  digest_0.6.23    
 [6] lmtest_0.9-37     R6_2.4.1          evaluate_0.14     highr_0.8         httr_1.4.1       
[11] pillar_1.4.3      rlang_0.4.3       lazyeval_0.2.2    curl_4.3          rstudioapi_0.10  
[16] fracdiff_1.5-1    TTR_0.23-6        rmarkdown_2.1     labeling_0.3      webshot_0.5.2    
[21] readr_1.3.1       stringr_1.4.0     munsell_0.5.0     anytime_0.3.7     compiler_3.6.0   
[26] xfun_0.12         pkgconfig_2.0.3   urca_1.3-0        htmltools_0.4.0   nnet_7.3-12      
[31] tidyselect_0.2.5  gridExtra_2.3     quadprog_1.5-8    viridisLite_0.3.0 fansi_0.4.1      
[36] crayon_1.3.4      withr_2.1.2       grid_3.6.0        nlme_3.1-143      gtable_0.3.0     
[41] lifecycle_0.1.0   magrittr_1.5      scales_1.1.0      quantmod_0.4-15   cli_2.0.1        
[46] stringi_1.4.5     farver_2.0.3      tseries_0.10-47   timeDate_3043.102 ggfortify_0.4.8  
[51] xml2_1.2.2        ellipsis_0.3.0    xts_0.12-0        generics_0.0.2    vctrs_0.2.2      
[56] tools_3.6.0       glue_1.3.1        purrr_0.3.3       hms_0.5.3         parallel_3.6.0   
[61] yaml_2.2.0        colorspace_1.4-1  rvest_0.3.5      

Thanks

Barry

I cannot reproduce this as I don't have access to your data. Please create a minimal reproducible example for this to help me help you.

Trying similar code on the WWWusage dataset works fine:

library(forecast)
#> Registered S3 method overwritten by 'quantmod':
#>   method            from
#>   as.zoo.data.frame zoo

trend <- seq_along(WWWusage)
fit1 <- auto.arima(WWWusage, d=0, xreg=trend)
fit2 <- auto.arima(WWWusage,d=1)
fc1 <- forecast(fit1, xreg=length(trend) + 1:10)
fc2 <- forecast(fit2, h=10)
autoplot(WWWusage) +
  autolayer(fc2) +
  autolayer(fc1)

Created on 2020-02-29 by the reprex package (v0.3.0)

Session info
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 3.6.2 (2019-12-12)
#>  os       Ubuntu 18.04.4 LTS          
#>  system   x86_64, linux-gnu           
#>  ui       X11                         
#>  language en_AU:en                    
#>  collate  en_AU.UTF-8                 
#>  ctype    en_AU.UTF-8                 
#>  tz       Australia/Melbourne         
#>  date     2020-02-29                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version     date       lib source                         
#>  assertthat    0.2.1       2019-03-21 [1] CRAN (R 3.6.1)                 
#>  backports     1.1.5       2019-10-02 [1] CRAN (R 3.6.1)                 
#>  callr         3.4.1       2020-01-24 [1] CRAN (R 3.6.2)                 
#>  cli           2.0.1       2020-01-08 [1] RSPM (R 3.6.2)                 
#>  colorspace    1.4-1       2019-03-18 [1] CRAN (R 3.6.1)                 
#>  crayon        1.3.4       2017-09-16 [1] CRAN (R 3.6.1)                 
#>  curl          4.3         2019-12-02 [1] CRAN (R 3.6.1)                 
#>  desc          1.2.0       2018-05-01 [1] CRAN (R 3.6.1)                 
#>  devtools      2.2.1       2019-09-24 [1] CRAN (R 3.6.1)                 
#>  digest        0.6.25      2020-02-23 [1] RSPM (R 3.6.2)                 
#>  dplyr         0.8.4       2020-01-31 [1] RSPM (R 3.6.2)                 
#>  ellipsis      0.3.0       2019-09-20 [1] CRAN (R 3.6.1)                 
#>  evaluate      0.14        2019-05-28 [1] CRAN (R 3.6.1)                 
#>  fansi         0.4.1       2020-01-08 [1] RSPM (R 3.6.2)                 
#>  farver        2.0.3       2020-01-16 [1] CRAN (R 3.6.1)                 
#>  forecast    * 8.11.0.9000 2020-02-22 [1] local                          
#>  fracdiff      1.5-0       2019-12-09 [1] RSPM (R 3.6.1)                 
#>  fs            1.3.1       2019-05-06 [1] CRAN (R 3.6.1)                 
#>  ggplot2       3.2.1       2019-08-10 [1] RSPM (R 3.6.1)                 
#>  glue          1.3.1.9000  2020-02-22 [1] Github (tidyverse/glue@7131fc3)
#>  gtable        0.3.0       2019-03-25 [1] CRAN (R 3.6.1)                 
#>  highr         0.8         2019-03-20 [1] CRAN (R 3.6.1)                 
#>  htmltools     0.4.0       2019-10-04 [1] CRAN (R 3.6.1)                 
#>  httr          1.4.1       2019-08-05 [1] CRAN (R 3.6.1)                 
#>  knitr         1.27        2020-01-16 [1] CRAN (R 3.6.1)                 
#>  labeling      0.3         2014-08-23 [1] CRAN (R 3.6.1)                 
#>  lattice       0.20-38     2018-11-04 [2] CRAN (R 3.6.2)                 
#>  lazyeval      0.2.2       2019-03-15 [1] CRAN (R 3.6.1)                 
#>  lifecycle     0.1.0       2019-08-01 [1] CRAN (R 3.6.1)                 
#>  lmtest        0.9-37      2019-04-30 [1] CRAN (R 3.6.1)                 
#>  magrittr      1.5         2014-11-22 [1] CRAN (R 3.6.1)                 
#>  memoise       1.1.0       2017-04-21 [1] CRAN (R 3.6.1)                 
#>  mime          0.9         2020-02-04 [1] RSPM (R 3.6.2)                 
#>  munsell       0.5.0       2018-06-12 [1] CRAN (R 3.6.1)                 
#>  nlme          3.1-142     2019-11-07 [2] CRAN (R 3.6.2)                 
#>  nnet          7.3-12      2016-02-02 [2] CRAN (R 3.6.2)                 
#>  pillar        1.4.3.9000  2020-01-13 [1] Github (r-lib/pillar@8f5918c)  
#>  pkgbuild      1.0.6       2019-10-09 [1] CRAN (R 3.6.1)                 
#>  pkgconfig     2.0.3       2019-09-22 [1] CRAN (R 3.6.1)                 
#>  pkgload       1.0.2       2018-10-29 [1] CRAN (R 3.6.1)                 
#>  prettyunits   1.1.1       2020-01-24 [1] CRAN (R 3.6.2)                 
#>  processx      3.4.1       2019-07-18 [1] CRAN (R 3.6.1)                 
#>  ps            1.3.0       2018-12-21 [1] CRAN (R 3.6.1)                 
#>  purrr         0.3.3       2019-10-18 [1] CRAN (R 3.6.1)                 
#>  quadprog      1.5-8       2019-11-20 [1] CRAN (R 3.6.1)                 
#>  quantmod      0.4-15      2019-06-17 [1] CRAN (R 3.6.1)                 
#>  R6            2.4.1       2019-11-12 [1] CRAN (R 3.6.1)                 
#>  Rcpp          1.0.3       2019-11-08 [1] CRAN (R 3.6.1)                 
#>  remotes       2.1.0       2019-06-24 [1] CRAN (R 3.6.1)                 
#>  rlang         0.4.4.9000  2020-02-14 [1] Github (r-lib/rlang@4ca000c)   
#>  rmarkdown     2.1         2020-01-20 [1] CRAN (R 3.6.1)                 
#>  rprojroot     1.3-2       2018-01-03 [1] CRAN (R 3.6.1)                 
#>  scales        1.1.0       2019-11-18 [1] RSPM (R 3.6.1)                 
#>  sessioninfo   1.1.1       2018-11-05 [1] CRAN (R 3.6.1)                 
#>  stringi       1.4.6       2020-02-17 [1] CRAN (R 3.6.2)                 
#>  stringr       1.4.0       2019-02-10 [1] CRAN (R 3.6.1)                 
#>  testthat      2.3.1       2019-12-01 [1] CRAN (R 3.6.1)                 
#>  tibble        2.1.3       2019-06-06 [1] RSPM (R 3.6.1)                 
#>  tidyselect    1.0.0       2020-01-27 [1] RSPM (R 3.6.2)                 
#>  timeDate      3043.102    2018-02-21 [1] CRAN (R 3.6.1)                 
#>  tseries       0.10-47     2019-06-05 [1] CRAN (R 3.6.1)                 
#>  TTR           0.23-6      2019-12-15 [1] RSPM (R 3.6.1)                 
#>  urca          1.3-0       2016-09-06 [1] CRAN (R 3.6.1)                 
#>  usethis       1.5.1.9000  2020-01-31 [1] Github (r-lib/usethis@7d8b066) 
#>  withr         2.1.2       2018-03-15 [1] CRAN (R 3.6.1)                 
#>  xfun          0.12        2020-01-13 [1] RSPM (R 3.6.1)                 
#>  xml2          1.2.2       2019-08-09 [1] CRAN (R 3.6.1)                 
#>  xts           0.12-0      2020-01-19 [1] CRAN (R 3.6.1)                 
#>  yaml          2.2.1       2020-02-01 [1] RSPM (R 3.6.2)                 
#>  zoo           1.8-7       2020-01-10 [1] CRAN (R 3.6.1)                 
#> 
#> [1] /home/mitchell/R/x86_64-pc-linux-gnu-library/3.6
#> [2] /opt/R/3.6.2/lib/R/library

In attempting to produce a reproducible example I solved the issue which was located in my loaded environment.

Many thanks for your swift response.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.