我正在尝试从此website下载一个时间序列-这是我试图获取的最后一个项目。我正在使用 pdfetch ,因为它通常很快。只需输入该系列的代码即可完成工作。但是,这次我遇到了我无法解决的错误。在问题下方找到。
library(pdfetch)
pdfetch_ECB("ICP.M.U2.Y.XEFUN0.3.INX")
Error in xts(as.matrix(suppressWarnings(as.numeric(fr[, 2]))), dates, :
'order.by' cannot contain 'NA', 'NaN', or 'Inf'
有人能解决吗?
非常感谢!
我要包含我的SessionInfo:
R version 3.6.2 (2019-12-12)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)
Matrix products: default
Random number generation:
RNG: Mersenne-Twister
Normal: Inversion
Sample: Rounding
locale:
[1] LC_COLLATE=Italian_Italy.1252 LC_CTYPE=Italian_Italy.1252 LC_MONETARY=Italian_Italy.1252
[4] LC_NUMERIC=C LC_TIME=Italian_Italy.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] Quandl_2.10.0 tsDyn_10-1.2 tseries_0.10-47 quantmod_0.4-15 TTR_0.23-5
[6] xts_0.11-2 scales_1.0.0 stargazer_5.2.2 forecast_8.11 readxl_1.3.1
[11] dynlm_0.3-6 AER_1.2-9 survival_3.1-8 car_3.0-6 carData_3.0-3
[16] pdfetch_0.2.4 vars_1.5-3 lmtest_0.9-37 urca_1.3-0 strucchange_1.5-2
[21] sandwich_2.5-1 MASS_7.3-51.5 lubridate_1.7.4 zoo_1.8-6 pastecs_1.3.21
[26] rvest_0.3.5 xml2_1.2.2 ngram_3.0.4 quanteda_1.5.2 textstem_0.1.4
[31] koRpus.lang.en_0.1-3 koRpus_0.11-5 sylly_0.1-5 readtext_0.75 pdftools_2.3
[36] forcats_0.4.0 stringr_1.4.0 dplyr_0.8.4 purrr_0.3.2 readr_1.3.1
[41] tidyr_1.0.2 tibble_2.1.3 ggplot2_3.2.1 tidyverse_1.3.0 topicmodels_0.2-8
loaded via a namespace (and not attached):
[1] backports_1.1.4 fastmatch_1.1-0 plyr_1.8.4 selectr_0.4-2 lazyeval_0.2.2
[6] splines_3.6.2 digest_0.6.21 foreach_1.4.8 htmltools_0.4.0 fansi_0.4.0
[11] magrittr_1.5 tm_0.7-7 openxlsx_4.1.4 remotes_2.1.0 modelr_0.1.5
[16] RcppParallel_4.4.3 textshape_1.6.0 askpass_1.1 colorspace_1.4-1 haven_2.2.0
[21] xfun_0.12 crayon_1.3.4 jsonlite_1.6 iterators_1.0.12 glue_1.3.1
[26] stopwords_1.0 gtable_0.3.0 spacyr_1.2 abind_1.4-5 qpdf_1.1
[31] DBI_1.1.0 tseriesChaos_0.1-13.1 qdapRegex_0.7.2 Rcpp_1.0.2 foreign_0.8-74
[36] deSolve_1.27.1 Formula_1.2-3 textclean_0.9.3 stats4_3.6.2 httr_1.4.1
[41] modeltools_0.2-22 pkgconfig_2.0.3 XML_3.99-0.3 nnet_7.3-12 dbplyr_1.4.2
[46] utf8_1.1.4 janitor_1.2.1 tidyselect_0.2.5 labeling_0.3 rlang_0.4.4
[51] reshape2_1.4.3 munsell_0.5.0 cellranger_1.1.0 tools_3.6.2 cli_2.0.1
[56] generics_0.0.2 broom_0.5.4 evaluate_0.14 yaml_2.2.0 knitr_1.26
[61] fs_1.3.1 zip_2.0.4 nlme_3.1-143 slam_0.1-45 compiler_3.6.2
[66] rstudioapi_0.11 curl_4.1 reprex_0.3.0 syuzhet_1.0.4 stringi_1.4.3
[71] lattice_0.20-38 Matrix_1.2-18 vctrs_0.2.2 pillar_1.4.3 lifecycle_0.1.0
[76] data.table_1.12.2 sylly.en_0.1-3 R6_2.4.1 rio_0.5.16 lexicon_1.2.1
[81] codetools_0.2-16 boot_1.3-24 assertthat_0.2.1 withr_2.1.2 mnormt_1.5-6
[86] fracdiff_1.5-1 mgcv_1.8-31 parallel_3.6.2 hms_0.5.3 ISOcodes_2019.12.22
[91] quadprog_1.5-8 grid_3.6.2 timeDate_3043.102 rmarkdown_2.1 NLP_0.2-0
答案 0 :(得分:2)
这似乎是一个语言环境问题,最可能的原因是lubridate无法解析您的语言环境中downloaded csv document的不寻常的英语年-月格式。
我可以这样做来复制您的错误
Sys.setlocale("LC_ALL", "Italian_Italy.1252")
pdfetch_ECB("ICP.M.U2.Y.XEFUN0.3.INX")
#> Error in xts(as.matrix(suppressWarnings(as.numeric(fr[, 2]))), dates, :
#> 'order.by' cannot contain 'NA', 'NaN', or 'Inf'
并通过进行修复
Sys.setlocale("LC_ALL", "English_United Kingdom.1252")
pdfetch_ECB("ICP.M.U2.Y.XEFUN0.3.INX")
#> ICP.M.U2.Y.XEFUN0.3.INX
#> 1997-01-31 75.45
#> 1997-02-28 75.52
#> 1997-03-31 75.59
#> 1997-04-30 75.61
#> 1997-05-31 75.71
#> 1997-06-30 75.76
#> ...
所以这应该对您有用:
Sys.setlocale("LC_ALL", "English_United Kingdom.1252")
result <- pdfetch_ECB("ICP.M.U2.Y.XEFUN0.3.INX")
Sys.setlocale("LC_ALL", "Italian_Italy.1252")