首页 > 解决方案 > 运行脚本后,我在下面收到一条警告消息

问题描述

为什么以下脚本会产生以下警告?

portfolioPrices <- NULL
for (ticker in tickers) {
  portfolioPrices <- cbind(portfolioPrices, getSymbols.yahoo(ticker, from='2016-02-19', periodicity = 
  'daily', auto.assign=FALSE)[,4])
}

警告:

1: 'indexClass<-' is deprecated.
Use 'tclass<-' instead.
See help("Deprecated") and help("xts-deprecated"). 
2: 'indexClass<-' is deprecated.
Use 'tclass<-' instead.
See help("Deprecated") and help("xts-deprecated"). 

标签: r

解决方案


通常的建议是让您提供 MWE……我们可以没有这里。

您现在可以放心地忽略这些警告消息,请注意,如果quantmod库维护者不更新他们的包以满足xts库中的更改,这可能会在(近乎?)将来停止工作1
要忽略上述警告,如果您想防止它们被打印到控制台 ,您可以将您的getSybmols呼叫包装起来。suppressWarnings

Joshua Ulrich 负责这个包,并在一段时间前xts进行了更改:请参阅 2018 年 4 月 20 日在 GitHub 上的提交indexClasstclass

1作为维护良好的软件包的示例,您可以查看Brian Peterson 的 Quantstrat 软件包以及他如何替换indexClasstclass,基本上解决了您在 中看到的警告quantmod


推荐阅读