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 |
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.
bacen_api(url, httr = TRUE)
bacen_api(url, httr = TRUE)
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'. |
Returns the data retrieved from the BACEN API.
# 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)
# 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)
This function retrieves data from multiple Central Bank series, given a vector of series IDs and corresponding names.
bacen_series(series, names, start_date, end_date, httr = TRUE)
bacen_series(series, names, start_date, end_date, httr = TRUE)
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'. |
A 'data.frame' containing the retrieved series data.
series <- c('433', '13005') names <- c('ipca_br', 'ipca_for') data <- bacen_series(series, names, "01/01/2013", "31/12/2023", httr = TRUE)
series <- c('433', '13005') names <- c('ipca_br', 'ipca_for') data <- bacen_series(series, names, "01/01/2013", "31/12/2023", httr = TRUE)
This function generates URLs to access specific time series data provided by the Central Bank of Brazil API.
bacen_url(series, start_date, end_date)
bacen_url(series, start_date, end_date)
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". |
Returns a vector containing the generated URLs for each provided series.
# Generate a URL for series 433 (IPCA) from 01/01/2003 to 31/12/2023. bacen_url(433, "01/01/2013", "31/12/2023")
# Generate a URL for series 433 (IPCA) from 01/01/2003 to 31/12/2023. bacen_url(433, "01/01/2013", "31/12/2023")