sboysel / fredr

An R client for the Federal Reserve Economic Data (FRED) API
https://sboysel.github.io/fredr/
Other
92 stars 21 forks source link

Parse and return `realtime_start` and `realtime_end` columns #91

Closed DavisVaughan closed 3 years ago

DavisVaughan commented 3 years ago

Part of #88 and #89

We now always return realtime_start and realtime_end columns in fredr_series_observations()

library(fredr)

# we now know how to differentiate the duplicate dates based on realtime_*
fredr_series_observations(
  series_id = "GDPC1",
  observation_start = as.Date("2000-01-01"),
  vintage_dates = as.Date(c("2001-01-01", "2002-01-01"))
)
#> # A tibble: 10 x 5
#>    date       series_id value realtime_start realtime_end
#>    <date>     <chr>     <dbl> <date>         <date>      
#>  1 2000-01-01 GDPC1     9192. 2001-01-01     2001-07-26  
#>  2 2000-01-01 GDPC1     9102. 2001-07-27     2002-01-01  
#>  3 2000-04-01 GDPC1     9319. 2001-01-01     2001-07-26  
#>  4 2000-04-01 GDPC1     9229. 2001-07-27     2002-01-01  
#>  5 2000-07-01 GDPC1     9370. 2001-01-01     2001-07-26  
#>  6 2000-07-01 GDPC1     9260. 2001-07-27     2002-01-01  
#>  7 2000-10-01 GDPC1     9304. 2001-07-27     2002-01-01  
#>  8 2001-01-01 GDPC1     9334. 2001-07-27     2002-01-01  
#>  9 2001-04-01 GDPC1     9342. 2001-09-28     2002-01-01  
#> 10 2001-07-01 GDPC1     9310. 2001-12-21     2002-01-01

# for consistency, we always return the realtime_start/end columns.
# they are set to the current date if not specified
fredr_series_observations(
  series_id = "GDPC1",
  observation_start = as.Date("2000-01-01")
)
#> # A tibble: 83 x 5
#>    date       series_id  value realtime_start realtime_end
#>    <date>     <chr>      <dbl> <date>         <date>      
#>  1 2000-01-01 GDPC1     12924. 2021-01-12     2021-01-12  
#>  2 2000-04-01 GDPC1     13161. 2021-01-12     2021-01-12  
#>  3 2000-07-01 GDPC1     13178. 2021-01-12     2021-01-12  
#>  4 2000-10-01 GDPC1     13261. 2021-01-12     2021-01-12  
#>  5 2001-01-01 GDPC1     13223. 2021-01-12     2021-01-12  
#>  6 2001-04-01 GDPC1     13300. 2021-01-12     2021-01-12  
#>  7 2001-07-01 GDPC1     13245. 2021-01-12     2021-01-12  
#>  8 2001-10-01 GDPC1     13281. 2021-01-12     2021-01-12  
#>  9 2002-01-01 GDPC1     13397. 2021-01-12     2021-01-12  
#> 10 2002-04-01 GDPC1     13478. 2021-01-12     2021-01-12  
#> # … with 73 more rows

Created on 2021-01-12 by the reprex package (v0.3.0.9001)