Quantmod 错误 'cannot open URL'

Quantmod Error 'cannot open URL'

我今天开始遇到 quantmod 包的错误。当 运行 此代码(或一般请求符号)时,其他人有同样的错误吗?

library(quantmod) getSymbols("CPIAUCNS",src="FRED")

错误:
Error in download.file(paste(FRED.URL, "/", Symbols[[i]], "/", "downloaddata/", : cannot open URL 'http://research.stlouisfed.org/fred2/series/CPIAUCNS/downloaddata/CPIAUCNS.csv'

URL 本身工作正常。

昨天出现的问题:
Cannot verify certificate for stlouisfed.org issued by GoDaddy.

解决方法:

temp = tempfile()

download.file(url="http://research.stlouisfed.org/fred2/series/DAAA/downloaddata/CPIAUCNS.csv",destfile=temp, method="libcurl")

result <- read.csv(temp,na.string=".")

我希望不得不使用此修复程序是暂时的。

FRED 将 URL 方案从 http:// 更改为 https://。我正在努力确定一个适用于所有平台的补丁。如果设置了 --internet2,当前代码在 Windows 上对我仍然有效。

在类似 unix 的系统上,一种可能的解决方案是将 method="curl"method="wget" 添加到 getSymbols.FRED 中的 download.file 调用。

另一个(临时)解决方案是在实际 getSymbols 脚本之前调用以下方法之一:

options(download.file.method="libcurl")

options(download.file.method="wget")

options(download.file.method="wininet")

第一个选项对我有用(Mac)。
感谢来自 Rmetrics 的 Paul Gilbert(底部 post)

假设您信任 FRED 的 SSL 证书,这是适合我的解决方案。

您需要做的就是在执行 getSymbols 之前添加以下额外的代码行:

options(download.file.method = "wget", download.file.extra = c("--no-check-certificate"))

示例:

getSymbols("M2", from = start_date, to = end_date, src = "FRED")

[1] "M2"

str(M2)

1980-11-03/2015-10-05 上的“xts”对象包含: 数据:num [1:1823, 1] 1591 1593 1596 1597 1596 ... - attr(*, "dimnames")=列表 2 ..$ : 空 ..$ : 字符 "M2" 由 class 的对象索引:[Date] TZ:UTC xts 属性:
清单 2 $ 来源:字符 "FRED" $ 更新:POSIXct[1:1],格式:“2015-10-21 11:01:39”