---
title: "FRED Sources"
author: "Sam Boysel"
date: "`r Sys.Date()`"
output: 
  rmarkdown::html_vignette:
    toc: true
    toc_depth: 3
vignette: >
  %\VignetteIndexEntry{FRED Sources}
  %\VignetteEncoding{UTF-8}
  %\VignetteEngine{knitr::rmarkdown}
editor_options: 
  chunk_output_type: console
---

```{r setup, include = FALSE}
library(fredr)

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

# Introduction

```{r}
library(fredr)
```

This vignette is intended to introduce the user to fredr functions for the [Sources endpoint](https://fred.stlouisfed.org/docs/api/fred/#Sources) of the FRED API.

FRED series are derived from a specific data **source**. Each FRED source is assigned an integer identifier. The following examples illustrate usage of the Sources endpoint functions in fredr.

## Get FRED sources

The function `fredr_sources()` returns a list of FRED data sources. The information returned is a tibble in which each row represents a FRED source. For example, running `fredr_sources()` without any arguments returns the first 1000 (`limit` default) sources ordered by ascending source ID (but here we limit to just 10):

```{r fredr_sources1}
fredr_sources(limit = 10)
```

## Get a single FRED source

The function `fredr_source()` returns information for a *single* source indicated by `source_id`. The data returned is a tibble in which each row represents a FRED source. For example, the Federal Financial Institutions Examination Council source ID is `6`:

```{r fredr_source1}
fredr_source(source_id = 6L)
```

## Get FRED releases for a source

The function `fredr_source_releases()` returns FRED release information for the source indicated by `source_id`. As with the functions for the [Releases endpoint](http://sboysel.github.io/fredr/reference/index.html#Releases), the data returned is a tibble in which each row represents a FRED release for the specified source. For example, to get the first 10 releases from the Federal Reserve Board of Governors, ordered by ascending release ID:

```{r fredr_source_releases1}
fredr_source_releases(
  source_id = 1L,
  limit = 10L
)
```

To get University of Michigan releases since 1950:

```{r fredr_source_releases2}
fredr_source_releases(
  source_id = 14L,
  realtime_start = as.Date("1950-01-01")
)
```
