1

I'm trying to download CPI data from FRED with tq_get from the tidyquant package.

This code retrieves the data from here: https://fred.stlouisfed.org/series/CPIAUCSL

cpi <- tq_get(x = c("CPIAUCSL"), get = "economic.data")

But the oldest date in the imported table is January 1, 2007. The data on FRED's website goes all the way back to January 1, 1947. Clicking "download" on the page I linked to downloads the entire series. Why doesn't tidyquant and is there a way to specify the desired date range?

John J.
  • 1,450
  • 1
  • 13
  • 28
  • 1
    `cpi <- tq_get(x = c("CPIAUCSL"), get = "economic.data", from="1947-01-01", to="2017-10-02")` Note that using another date (like from 1900-01-01) also works and doesn't throw an error - this could be useful if you don't know in advance when the data start – HFBrowning Oct 02 '17 at 20:06
  • 1
    In the future, check out `??FUNCTION` in the R interpreter for help and examples using a given function (since all I did was regurgitate what I found in `??tq_get`) – HFBrowning Oct 02 '17 at 20:12

2 Answers2

3

By default tq_get() returns 10-years of data. As @HFBrowning commented, you should add from and to arguments to specify a longer time range.

c("CPIAUCSL") %>% 
    tq_get(get = "economic.data", from="1947-01-01", to="2017-10-02") 
Matt Dancho
  • 6,840
  • 3
  • 35
  • 26
2

quantmod::getSymbols() (which tq_get calls) returns all the data by default.

cpi <- quantmod::getSymbols("CPIAUCSL", src="FRED", auto.assign=FALSE)
start(cpi)
# [1] "1947-01-01"
Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418