tidy-finance / r-tidyfinance

R package with helper functions for developers and researchers familiar with Tidy Finance
Other
13 stars 3 forks source link

Add function to download data from FRED #81

Closed christophscheuch closed 2 months ago

christophscheuch commented 2 months ago

Here is a quick prototype using existing depedencies:

library(httr2)
library(dplyr)

series <- "CPIAUCNS"
url <- paste0("https://fred.stlouisfed.org/series/", series, "/downloaddata/", series, ".csv")

response <- request(url) |> 
  req_perform()

resp_body_string(response) |> 
  textConnection() |>
  read.csv() |> 
  as_tibble() |> 
  mutate(date = as.Date(DATE),
         value = VALUE,
         series = series,
         .keep = "none")