我有大量使用 xts 对象的代码,升级到 R 4.0.0 后一切正常,但索引函数现在失败了。
如果我运行一个简单的脚本:
> class(SPY)
[1] "xts" "zoo"
> require(quantmod)
>
> getSymbols("SPY")
[1] "SPY"
>
> class(SPY)
[1] "xts" "zoo"
>
> index(SPY)
Error in if (type == "Date" || type == "yearmon" || type == "yearqtr") temp = as.Date(temp) :
missing value where TRUE/FALSE needed
。但是,如果我运行 index(as.zoo(SPY(( ->它按预期返回日期索引。
似乎无论与哪个版本的索引匹配,它都无法从 XTS 对象中提取 indexCLASS 值。
有人知道出了什么问题吗?我已经将索引包装在一个调用 zoo.index 的函数中,但这完全是一个黑客,不正确。
> sessionInfo()
R version 4.0.0 (2020-04-24)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.4
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
Random number generation:
RNG: Mersenne-Twister
Normal: Inversion
Sample: Rounding
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] parallel stats graphics grDevices utils datasets methods base
other attached packages:
[1] rugarch_1.4-2 Quandl_2.10.0 lubridate_1.7.8 quantmod_0.4.17 TTR_0.23-6 xts_0.12-0 zoo_1.8-8
loaded via a namespace (and not attached):
[1] Rcpp_1.0.4.6 MASS_7.3-51.5 mclust_5.4.6 lattice_0.20-41
[5] R6_2.4.1 Rsolnp_1.16 httr_1.4.1 GeneralizedHyperbolic_0.8-4
[9] tools_4.0.0 SkewHyperbolic_0.4-0 spd_2.0-1 grid_4.0.0
[13] KernSmooth_2.23-16 numDeriv_2016.8-1.1 Matrix_1.2-18 nloptr_1.2.2.1
[17] DistributionUtils_0.6-0 ks_1.11.7 curl_4.3 compiler_4.0.0
[21] generics_0.0.2 expm_0.999-4 jsonlite_1.6.1 truncnorm_1.0-8
[25] mvtnorm_1.1-0
当前的 xts 代码没有以下错误行,并且历史上从未存在过。
if (type == "Date" || type == "yearmon" || type == "yearqtr") temp = as.Date(temp)
所以我最好的猜测是,你的全局环境中有一个函数index.xts()
,其中包含错误的代码行。
您提到了indexCLASS
属性,该属性已在 xts 0.12.0 中删除。因此,掩码index.xts()
可能具有type <- attr(x, "indexCLASS")
,而不是使用indexClass()
(已弃用(或(首选(tclass()
函数。