library(fredr)

knitr::opts_chunk$set(
  fig.width = 7,
  fig.height = 5,
  eval = fredr_has_key(),
  collapse = TRUE,
  comment = "#>"
)

Introduction

library(fredr)

This vignette is intended to introduce the user to fredr functions for the Series endpoint of the FRED API.

FRED series are the primary data objects in the FRED database. Each FRED series is assigned a string identifier. For example:

FRED series are assigned categories and tags attributes for organization and classification. The following examples illustrate usage of the Series endpoint functions in fredr.

Retrieve observations

The function fredr(), an alias for fredr_series_observations(), is the core function in fredr for fetching FRED data series. See the Get started article and ?fredr() for many usage examples.

fredr(
  series_id = "UNRATE",
  observation_start = as.Date("1990-01-01")
)

Search for FRED series

Use fredr_series_search_text() to search for a series by text in the series description. The data returned is a tibble where each row represents series with description text that matches the text specified by search_text. For example, to search for series with description text that matches "UNRATE":

fredr_series_search_text(
  search_text = "unemployment",
  limit = 100L
)

Use fredr_series_search_id() to search for a series by character ID of the series. The data returned is a tibble where each row represents series with an ID that matches the text specified by search_text. For example, to search for series with an ID that matches "UNRATE":

fredr_series_search_id(
  search_text = "UNRATE",
  limit = 100L
)

Search for FRED series by tags

Use fredr_series_search_tags() to search for series tags. The data returned is a tibble where each row represents a tag matching the text in series_search_text. For example, to return the top 100 tags (by series count) matching the text "unemployment":

fredr_series_search_tags(
  series_search_text = "unemployment",
  limit = 100L
)

Search for FRED series by related tags

Use fredr_search_related_tags() to search for series tags related to a given tag. The data returned is a tibble where each row represents a tag who's series matches the text in series_search_text and related tags specified by tag_names. For example, to search for tags related to the tag "usa" in which the series text matches "gnp", use the following:

fredr_series_search_related_tags(
  series_search_text = "gnp",
  tag_names = "usa",
  limit = 30L
)

Get basic information for a FRED series

The fredr_series() function returns information for a single series specified by series_id. The data returned is a tibble in which each row represents the series specified. For example, to get information for the UNRATE series:

fredr_series(series_id = "UNRATE")

Note that there may potentially be more than one row returned if the series has been revised and real time periods are adjusted:

fredr_series(
  series_id = "UNRATE",
  realtime_start = as.Date("1950-01-01")
)

Get the categories for a FRED series

The fredr_series_categories() function returns a list of categories for the series specified by series_id. The data returned is a tibble in which each row represents a category that the series belongs to. For example, to get the categories for the UNRATE series:

fredr_series_categories(series_id = "UNRATE")

Get the release for a FRED series

The fredr_series_release() function returns a list of releases that the series specified by series_id belongs to. The data returned is a tibble in which each row represents a release that the series belongs to. For example, to get the release for the UNRATE series:

fredr_series_release(series_id = "UNRATE")

Get the tags for a FRED series

The fredr_series_tags() function returns a list of tags that are assigned to the series specified by series_id. The data returned is a tibble in which each row represents a tag assigned to the series. For example, to get the tags for the UNRATE series:

fredr_series_tags(
  series_id = "UNRATE",
  order_by = "name"
)

Get a set of recently updated FRED series

The fredr_series_updates() function returns a list of series recently updated on the FRED server. The data returned is a tibble in which each row represents a series. For example, the default call simply lists 1000 recent updates (the default for the limit parameter), most recent updates appearing first (but here we limit to 10):

fredr_series_updates(limit = 10L)

Use the start_time and end_time parameters to filter the results by time. For example, to get all the macroeconomic times series updated in the last day:

fredr_series_updates(
  start_time = Sys.time() - 60 * 60 * 24,
  end_time = Sys.time(),
  filter_value = "macro",
  limit = 10L
)

Get the vintage dates for a FRED series

The fredr_series_vintagedates() function returns a sequence of dates in history when the series specified by series_id was revised or appended to. The data returned is a tibble where each row is a date. For example, to get the vintage dates for the series UNRATE:

fredr_series_vintagedates(series_id = "UNRATE")


sboysel/fredr documentation built on Aug. 15, 2021, 9:19 a.m.