6

I started to experience an error today with the quantmod package. Anybody else have the same error when running this code (or requesting symbols in general)?

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

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

The URL itself works fine.

Wolf
  • 562
  • 1
  • 7
  • 19

4 Answers4

7

FRED changed the URL scheme from http:// to https://. I'm working on determining a patch that will work on all platforms. The current code still works for me on Windows if --internet2 is set.

On unix-alikes, one potential solution is to add method="curl" or method="wget" to the download.file call in getSymbols.FRED.

Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418
7

Another (temporary) solution is to call one of the following before the actual getSymbols script:

options(download.file.method="libcurl")
or
options(download.file.method="wget")
or
options(download.file.method="wininet")

The first option works for me (on Mac).
Thanks Paul Gilbert from Rmetrics (bottom post)

Wolf
  • 562
  • 1
  • 7
  • 19
2

The problem appeared yesterday:
Cannot verify certificate for stlouisfed.org issued by GoDaddy.

A workaround:

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=".")

I hope having to use this fix is temporary.

tumultous_rooster
  • 12,150
  • 32
  • 92
  • 149
Aditsan
  • 21
  • 1
2

Here is solution that works for me, assuming you trust FRED's SSL certificate.

All you need to do is adding the following extra line of code before executing getSymbols:

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

Example:

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

[1] "M2"

str(M2)

An ‘xts’ object on 1980-11-03/2015-10-05 containing: Data: num [1:1823, 1] 1591 1593 1596 1597 1596 ... - attr(*, "dimnames")=List of 2 ..$ : NULL ..$ : chr "M2" Indexed by objects of class: [Date] TZ: UTC xts Attributes:
List of 2 $ src : chr "FRED" $ updated: POSIXct[1:1], format: "2015-10-21 11:01:39"

Key
  • 21
  • 3