问题
I'm working through the Hyndman fpp3 package based on this markdown document. https://github.com/robjhyndman/ISI_Workshop_2019/blob/master/5_reconciliation/reconciliation.Rmd
I just couldn't find out why the following code fail to run
library(fpp3)
PBS %>%
aggregate_key(ATC1/ATC2, Scripts = sum(Scripts)) %>%
filter(Month == yearmonth("1991 Jul")) %>% print(n=18)
I keep receiving the following error each time I run the above.
New names:
* `` -> ...1
* `` -> ...2
* `` -> ...3
* `` -> ...4
* `` -> ...5
* ...
Error: `vars` must be a character vector
Run `rlang::last_error()` to see where the error occurred.
> rlang::last_error()
<error/rlang_error>
`vars` must be a character vector
Backtrace:
8. fabletools::aggregate_key(., ATC1/ATC2, Scripts = sum(Scripts))
2. tsibble::build_tsibble_meta(...)
10. dplyr::mutate(...)
20. tsibble:::retain_tsibble(mut_data, key(.data), index(.data))
21. tsibble:::duplicated_key_index(data, key, index)
22. dplyr::grouped_df(as_tibble(data), key)
Run `rlang::last_trace()` to see the full context.
> rlang::last_trace()
<error/rlang_error>
`vars` must be a character vector
Backtrace:
█
1. └─`%>%`(...)
2. ├─base::withVisible(eval(quote(`_fseq`(`_lhs`)), env, env))
3. └─base::eval(quote(`_fseq`(`_lhs`)), env, env)
4. └─base::eval(quote(`_fseq`(`_lhs`)), env, env)
5. └─`_fseq`(`_lhs`)
6. └─magrittr::freduce(value, `_function_list`)
7. └─function_list[[i]](value)
8. ├─fabletools::aggregate_key(., ATC1/ATC2, Scripts = sum(Scripts))
9. └─fabletools:::aggregate_key.tbl_ts(., ATC1/ATC2, Scripts = sum(Scripts))
10. └─`%>%`(...)
11. ├─base::withVisible(eval(quote(`_fseq`(`_lhs`)), env, env))
12. └─base::eval(quote(`_fseq`(`_lhs`)), env, env)
13. └─base::eval(quote(`_fseq`(`_lhs`)), env, env)
14. └─fabletools:::`_fseq`(`_lhs`)
15. └─magrittr::freduce(value, `_function_list`)
16. ├─base::withVisible(function_list[[k]](value))
17. └─function_list[[k]](value)
18. ├─dplyr::mutate(...)
19. └─tsibble:::mutate.tbl_ts(...)
20. └─tsibble:::retain_tsibble(mut_data, key(.data), index(.data))
21. └─tsibble:::duplicated_key_index(data, key, index)
22. └─dplyr::grouped_df(as_tibble(data), key)
I suspect this is due to some package dependencies.
the fpp3 library give me the following packages versin
> library(fpp3)
── Attaching packages ──────────────────────────────── fpp3 0.2 ──
✓ tibble 3.0.0 ✓ tsibble 0.8.6
✓ dplyr 0.8.99.9002 ✓ tsibbledata 0.1.0
✓ tidyr 1.0.2 ✓ feasts 0.1.3
✓ lubridate 1.7.8 ✓ fable 0.1.2.9000
✓ ggplot2 3.3.0
── Conflicts ─────────────────────────────────── fpp3_conflicts ──
x lubridate::date() masks base::date()
x dplyr::filter() masks stats::filter()
x tsibble::id() masks dplyr::id()
x tsibble::interval() masks lubridate::interval()
x dplyr::lag() masks stats::lag()
session info
> sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux Server 7.6 (Maipo)
Matrix products: default
BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] 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
[7] base
other attached packages:
[1] fable_0.1.2.9000 feasts_0.1.3 fabletools_0.1.3
[4] tsibbledata_0.1.0 tsibble_0.8.6 ggplot2_3.3.0
[7] lubridate_1.7.8 tidyr_1.0.2 dplyr_0.8.99.9002
[10] tibble_3.0.0 fpp3_0.2
loaded via a namespace (and not attached):
[1] Rcpp_1.0.4.6 rstudioapi_0.11 magrittr_1.5
[4] tidyselect_1.0.0 munsell_0.5.0 anytime_0.3.7
[7] colorspace_1.4-1 R6_2.4.1 rlang_0.4.5.9000
[10] fansi_0.4.1 tools_3.6.0 grid_3.6.0
[13] gtable_0.3.0 cli_2.0.2 withr_2.1.2
[16] ellipsis_0.3.0 assertthat_0.2.1 lifecycle_0.2.0
[19] crayon_1.3.4 purrr_0.3.3 vctrs_0.2.99.9011
[22] glue_1.4.0 compiler_3.6.0 pillar_1.4.3
[25] generics_0.0.2 scales_1.1.0 pkgconfig_2.0.3
回答1:
It works using current CRAN versions of packages. You're using github versions of fable, dplyr, rlang & vctrs, but CRAN versions of everything else, and there are inconsistencies as a result.
来源:https://stackoverflow.com/questions/61229355/rlang-fpp3-r-package-error-vars-must-be-a-character-vector-upon-calling-agg