# bacenR

The {bacenR} package provides tools to download and process data from the Brazilian Central Bank (Banco Central do Brasil — Bacen) in a simple and efficient way. Currently, the package includes the following functions:

- `get_balance_sheets()`: download balance sheets from financial institutions

    get_balance_sheets(
      institution = c("BANCOS", "COOPERATIVAS"),
      months = c(6, 12),
      first_year = 2022,
      final_year = 2023,
      out_dir = tempdir(),
      overwrite = FALSE
    )

- `tidy_balance_sheets()`: process downloaded balance sheets with `get_balance_sheets()` and combine them into a single, unified file

    # First, download balance sheets
    get_balance_sheets(
      institution = c("BANCOS", "COOPERATIVAS"),
      months = 12,
      first_year = 2022,
      final_year = 2023,
      out_dir = tempdir(),
      overwrite = FALSE
    )

    # Now, tidy the files
    tidy_balance_sheets(
      path_raw = tempdir(),
      out_dir = tempdir(),
      doc_filter = 4010,
      save = FALSE
    )

- `get_normative_data()`: download regulatory metadata

    normas <- get_normative_data(
     terms = c("Cooperativas", "Cooperativa"),
     ini_date = "2025-01-01",
     end_date = "2025-12-12"
     )

- `get_normative_txt()`: download the full texts of regulatory instructions

    # First, download normative data
    normative_data <- get_normative_data(
       terms = "Cooperativa",
       ini_date = "2023-08-01",
       end_date = "2023-12-10"
    )

    # Then, download the full texts for the retrieved normatives
    normative_txt <- get_normative_txt(normative_data)

- `get_institutions()`: download information about institutions regulated by Bacen in activity

    # Download multiple institution types
    get_institutions(
      institution = c("BANCOS", "COOPERATIVAS"),
      start_date = "202201",
      end_date = "202212",
      out_dir = tempdir()
    )

- `tidy_institutions()`: precess the data downloaded with `get_institutions()` and combine them into a single, unified file

    # First, download institution data
     get_institutions(
      institution = "COOPERATIVAS",
      start_date = "202311",
      end_date = "202312",
      out_dir = tempdir()
    )

    # Process institution files from a directory
    institutions <- tidy_institutions(
      path_dir = tempdir(),
      out_dir = tempdir(),
      verbose = TRUE
    )

- `get_ifdata_reports()`: download IFdata Reports for specific periods and institution types. See also IFdata Reports interface.

    # Multiple periods
    cc_ativa_pj_modalidade_20142024 <- bacenR::get_ifdata_reports(
      year = c(2014:2024),
      month = 12,
      report = 13,
      type_institution = 2
    )

- `get_ifdata_registry()`: download IFdata Registry data for specified years and months.

    # Multiple years and months
    data <- get_ifdata_registry(
      year = c(2023, 2024),
      month = c(6, 12)
    )

For more details and examples, see the project on GitHub: https://github.com/rtheodoro/bacenR