| Title: | Deflate Nominal Brazilian Reais |
|---|---|
| Description: | Simple functions to deflate nominal Brazilian Reais using several popular price indexes downloaded from the Brazilian Institute for Applied Economic Research. |
| Authors: | Fernando Meireles [aut, cre] (ORCID: <https://orcid.org/0000-0002-7027-2058>) |
| Maintainer: | Fernando Meireles <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.2.0 |
| Built: | 2026-06-02 07:20:55 UTC |
| Source: | https://github.com/meirelesff/deflatebr |
Functions to handle API interactions with IPEA's database for price index data.
.IPEA_BASE_URL.IPEA_BASE_URL
An object of class character of length 1.
Checks if a cache file exists for the given index and validates its structure.
cache_exists(index, verbose = TRUE)cache_exists(index, verbose = TRUE)
index |
Character string indicating the price index. |
verbose |
Logical indicating whether to show cache status messages. |
Logical indicating whether a valid cache file exists.
deflate() is the main function of the deflateBR package. It uses data from the Brazilian Institute for Applied Economic Research's API (IPEADATA) to adjust nominal Brazilian Reais for inflation using various Brazilian price indexes.
deflate( nominal_values, nominal_dates, real_date, index = c("ipca", "igpm", "igpdi", "ipc", "inpc"), verbose = TRUE, cache = TRUE )deflate( nominal_values, nominal_dates, real_date, index = c("ipca", "igpm", "igpdi", "ipc", "inpc"), verbose = TRUE, cache = TRUE )
nominal_values |
A |
nominal_dates |
A |
real_date |
A reference date to deflate nominal values. Can be either:
|
index |
Indicates the price index used to deflate nominal Reais. Valid options are: |
verbose |
Logical indicating whether to show progress messages and progress bar during data download. Default is TRUE. |
cache |
Logical indicating whether to use local caching to store downloaded price index data. When TRUE, data is saved locally and reused in subsequent calls, improving performance. Default is TRUE. |
Each one of the five price indexes included in the function are maintained by two Brazilian agencies: IPCA and INPC indexes are maintained by Brazilian Institute of Geography and Statistics (IBGE); IGP-M, IGP-DI, and IPC are maintained by Getulio Vargas Foundation (FGV). For an overview of the indexes' methodologies and covered periods, check the Brazilian Central Bank official FAQ.
A numeric vector.
For more information on the Brazilian Institute for Applied Economic Research's API, please check (in Portuguese): http://www.ipeadata.gov.br/.
## Not run: # Use IPCA index to deflate a vector of nominal Brazilian Reais reais <- rep(100, 5) actual_dates <- seq.Date(from = as.Date("2001-01-01"), to = as.Date("2001-05-01"), by = "month") # Using character string for reference date deflate(reais, actual_dates, "01/2018", "ipca") # Using Date object for reference date deflate(reais, actual_dates, as.Date("2018-01-01"), "ipca") # Using IGP-M index deflate(reais, actual_dates, "01/2018", "igpm") # Silent operation without progress messages deflate(reais, actual_dates, as.Date("2018-01-01"), "ipca", verbose = FALSE) # Disable caching (always download fresh data) deflate(reais, actual_dates, "01/2018", "ipca", cache = FALSE) ## End(Not run)## Not run: # Use IPCA index to deflate a vector of nominal Brazilian Reais reais <- rep(100, 5) actual_dates <- seq.Date(from = as.Date("2001-01-01"), to = as.Date("2001-05-01"), by = "month") # Using character string for reference date deflate(reais, actual_dates, "01/2018", "ipca") # Using Date object for reference date deflate(reais, actual_dates, as.Date("2018-01-01"), "ipca") # Using IGP-M index deflate(reais, actual_dates, "01/2018", "igpm") # Silent operation without progress messages deflate(reais, actual_dates, as.Date("2018-01-01"), "ipca", verbose = FALSE) # Disable caching (always download fresh data) deflate(reais, actual_dates, "01/2018", "ipca", cache = FALSE) ## End(Not run)
Returns a named vector of available price index codes and their corresponding series codes.
get_available_indexes()get_available_indexes()
A named character vector where names are index identifiers and values are series codes.
Functions to handle local caching of price index data to improve performance by avoiding redundant API calls. Get Cache Directory Path
Returns the path to the cache directory, creating it if it doesn't exist.
get_cache_dir(create_if_missing = TRUE)get_cache_dir(create_if_missing = TRUE)
create_if_missing |
Logical indicating whether to create the directory if it doesn't exist. |
Character string with the path to the cache directory.
Returns the full path to the cache file for a specific price index.
get_cache_file_path(index)get_cache_file_path(index)
index |
Character string indicating the price index. |
Character string with the full path to the cache file.
Fetches price index data from IPEA's API with retry mechanism and proper error handling.
get_price_index_data(index, max_retries = 3, retry_delay = 1, verbose = TRUE)get_price_index_data(index, max_retries = 3, retry_delay = 1, verbose = TRUE)
index |
Character string indicating the price index. Valid options are: "ipca", "igpm", "igpdi", "ipc", "inpc". |
max_retries |
Maximum number of retry attempts for failed requests. Default is 3. |
retry_delay |
Delay in seconds between retry attempts. Default is 1. |
verbose |
Logical indicating whether to show progress messages and progress bar. Default is TRUE. |
A data frame with columns VALDATA (dates) and VALVALOR (index values).
Main function that handles cache logic - checks cache first, then downloads if needed.
get_price_index_data_cached( index, cache = TRUE, verbose = TRUE, max_retries = 3, retry_delay = 1 )get_price_index_data_cached( index, cache = TRUE, verbose = TRUE, max_retries = 3, retry_delay = 1 )
index |
Character string indicating the price index. |
cache |
Logical indicating whether to use caching. |
verbose |
Logical indicating whether to show progress messages. |
max_retries |
Maximum number of retry attempts for failed requests. |
retry_delay |
Delay in seconds between retry attempts. |
A data frame with columns VALDATA (dates) and VALVALOR (index values).
Loads price index data from the local cache file.
load_from_cache(index, verbose = TRUE)load_from_cache(index, verbose = TRUE)
index |
Character string indicating the price index. |
verbose |
Logical indicating whether to show cache loading messages. |
A data frame with columns VALDATA (dates) and VALVALOR (index values).
Saves price index data to the local cache file.
save_to_cache(index, data, verbose = TRUE)save_to_cache(index, data, verbose = TRUE)
index |
Character string indicating the price index. |
data |
Data frame with price index data to cache. |
verbose |
Logical indicating whether to show cache saving messages. |
Logical indicating success of the caching operation.