R/get_data_indicators.R

Defines functions get_data_indicators

Documented in get_data_indicators

#' @title Imports data relating to key US economic indicators over time
#' @description This function enables you to import data relating to key US economic indicators over time.
#' @keywords data
#' @examples
#' \dontrun{
#' get_data_indicators()
#' }
#'
#' @importFrom rlang .data
get_data_indicators <- function(){
  
  data_economy <- tidyquant::tq_get(
    x = c(
      "T10YIE",  # 10 Yr Breakeven
      "OB000334Q" # Real Y-O-Y GDP
    ),
    get = "economic.data",
    from = "2002-01-01"
  ) |> 
    dplyr::mutate(
      series = dplyr::if_else(
        .data$symbol == "T10YIE", 
        "10 Yr Breakeven", 
        "Real Y-O-Y GDP"
      ),
      level = .data$price / 100
    ) |> 
    dplyr::select(-.data$symbol, -.data$price) |> 
    tsibble::as_tsibble(key = .data$series, index = .data$date) 

  return(data_economy)
  
}
p0bs/shiny.moduler documentation built on Oct. 21, 2023, 9:24 p.m.