tidy_ifdata_reports: Tidy ifdata Reports Data

View source: R/tidy_ifdata_reports.R

tidy_ifdata_reportsR Documentation

Tidy ifdata Reports Data

Description

[Stable]

Transforms raw ifdata reports downloaded with get_ifdata_reports() into a clean, wide-format dataset suitable for analysis. This function handles data input from multiple sources (direct data.frame), removes unnecessary columns, renames identifiers, and pivots the data from long to wide format.

Usage

tidy_ifdata_reports(data)

Arguments

data

Optional. A data.frame/tibble. The data must be downloaded via get_ifdata_reports. If a data.frame, it should contain the raw ifdata reports structure with columns: cod_inst, grupo, conta, numero_relatorio, nome_relatorio, tipo_instituicao, descricao_coluna, nome_coluna, and saldo.

Details

The function performs the following operations in sequence:

  1. Data Input Handling: Accepts data in two forms:

    • Direct tibble/data.frame (preferred for in-memory operations)

  2. Column Removal: Drops metadata columns that are redundant after pivoting (grupo, conta, numero_relatorio, etc.)

  3. Identifier Rename: Renames cod_inst to cnpj for clarity that rows represent financial institutions by their CNPJ identifier

  4. Pivot Operation: Transforms from long format (each report metric in a separate row) to wide format (each metric becomes a column). The pivot uses nome_coluna for column names and saldo for cell values.

  5. Name Cleaning: Applies janitor's name standardization to ensure consistent, R-friendly column naming

Value

A tibble with the following transformations applied:

  • Columns removed: grupo, conta, numero_relatorio, nome_relatorio, tipo_instituicao, descricao_coluna

  • Column renamed: cod_inst → cnpj

  • Structure pivoted: Long format (multiple rows per institution) → Wide format (one row per institution with columns for each report item)

  • Column names: Cleaned to lowercase with underscores via clean_names

See Also

get_ifdata_reports for downloading raw data

Examples


# Tidy an existing data.frame
raw_data <- get_ifdata_reports(year = 2024, month = 12, 
                                type_institution = 2, report = 4)
tidy_data <- tidy_ifdata_reports(data = raw_data)



bacenR documentation built on Oct. 24, 2026, 1:07 a.m.