tidy_institutions: Process and unify institution CSV exports from the Brazilian...

View source: R/tidy_institutions.R

tidy_institutionsR Documentation

Process and unify institution CSV exports from the Brazilian Central Bank (Bacen) downloaded via get_institutions().

Description

[Stable]

This function reads and processes financial institutions data from the Brazilian Central Bank (Bacen) files that were previously downloaded using the get_institutions() function. It takes a directory path containing the institution files, processes them, and optionally saves the output to a specified directory.

Usage

tidy_institutions(path_dir, out_dir, verbose = TRUE)

Arguments

path_dir

Character string specifying the path to the directory containing institution files to be processed.

out_dir

Character string specifying the path to the directory where processed output files should be saved.

verbose

Logical value indicating whether to print progress messages during processing. Default is typically FALSE.

Details

Bacen changes column headers over the years. After janitor::clean_names(), columns are renamed to the most recent header so each institution type has a single column per field:

  • All types: nome, nomeinstituicao -> nome_instituicao; fone -> telefone; cidade -> municipio; segmentos -> segmento.

  • E-mail and website columns (email, e_mail, endereco_eletronico, sitio_na_internet, end_pagina_internet) are assigned to e_mail or sitio_na_internet by their content (share of values containing "@"), because Bacen's headers for them are inconsistent and sometimes swapped.

  • COOPERATIVAS: classe_cooper -> classe.

  • CONGLOMERADOS: nome_conglomerado -> nome_do_conglomerado; classe -> classe_do_conglomerado; nome_instituicao_participante, nome_participante -> nome_do_participante; dt_inicio -> data_inicio (converted to Date); estado -> uf.

Columns that are not equivalent across years (e.g. COOPERATIVAS tipo_cooperativa until 2015 and criterio_de_associacao from 2016) are kept separate.

Value

A list of data.frames, where each element corresponds to a processed institution file. The names of the list elements typically correspond to institution identifiers or file names.

Examples

# First, download institution data
# Download cooperative credit unions data for 2023
get_institutions(
  institution = "COOPERATIVAS",
  years = 2023,
  months = 11:12,
  out_dir = tempdir()
)
# Process institution files from a directory
institutions <- tidy_institutions(
  path_dir = tempdir(),
  out_dir = tempdir(),
  verbose = TRUE
)

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