Package 'BacenAPI'

Title: Tools for Accessing and Using Data from the Central Bank of Brazil
Description: Provides tools to facilitate the access and processing of data from the Central Bank of Brazil API. The package allows users to retrieve economic and financial data, transforming them into usable tabular formats for further analysis.
Authors: Paulo Icaro [aut], Lissandro Sousa [cre, aut]
Maintainer: Lissandro Sousa <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2025-03-08 06:43:52 UTC
Source: https://github.com/lissandrosousa/bacenapi

Help Index


Connection to the Central Bank API

Description

This function establishes a connection with the Central Bank of Brazil (BACEN) API, using the 'httr' or 'httr2' packages to retrieve data in JSON format and convert it into a readable format such as data frames.

Usage

bacen_api(url, httr = TRUE)

Arguments

url

A string containing the BACEN API URL for the desired series.

httr

A logical value. If 'TRUE', the function uses the 'httr' package for the connection. Otherwise, it uses the 'httr2' package. The default value is 'TRUE'.

Value

Returns the data retrieved from the BACEN API.

Examples

# Example using the `httr` package:
url <- bacen_url(433, "01/01/2013", "31/12/2023") # in the format "dd/mm/yyyy"
data <- bacen_api(url, httr = TRUE)

# Example using the `httr2` package:
data <- bacen_api(url, httr = FALSE)

Fetch Multiple Central Bank Series

Description

This function retrieves data from multiple Central Bank series, given a vector of series IDs and corresponding names.

Usage

bacen_series(series, names, start_date, end_date, httr = TRUE)

Arguments

series

A numeric vector containing the series IDs from Central Bank API.

names

A character vector containing the names corresponding to each series.

start_date

A string specifying the start date in "dd/mm/yyyy" format.

end_date

A string specifying the end date in "dd/mm/yyyy" format.

httr

A logical value indicating whether to use 'httr' ('TRUE') or 'httr2' ('FALSE'). Default is 'TRUE'.

Value

A 'data.frame' containing the retrieved series data.

Examples

series <- c('433', '13005')
names <- c('ipca_br', 'ipca_for')
data <- bacen_series(series, names, "01/01/2013", "31/12/2023", httr = TRUE)

Creation of URLs to Access the Central Bank API

Description

This function generates URLs to access specific time series data provided by the Central Bank of Brazil API.

Usage

bacen_url(series, start_date, end_date)

Arguments

series

Desired series code(s). Must be a number or a vector of numbers.

start_date

Start date of the period of interest, in the format "dd/mm/yyyy".

end_date

End date of the period of interest, in the format "dd/mm/yyyy".

Value

Returns a vector containing the generated URLs for each provided series.

Examples

# Generate a URL for series 433 (IPCA) from 01/01/2003 to 31/12/2023.
bacen_url(433, "01/01/2013", "31/12/2023")