## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")

## ----eval = FALSE-------------------------------------------------------------
# # From CRAN (when available):
# install.packages("estbanr")
# 
# # Development version:
# # remotes::install_github("StrategicProjects/estbanr")

## -----------------------------------------------------------------------------
library(estbanr)

f <- system.file("extdata", "202401_ESTBAN_AG_sample.CSV", package = "estbanr")
x <- estban_read(f)
x[, 1:8]

## -----------------------------------------------------------------------------
x[1:3, c("municipio", "nome_instituicao", "verbete_160_operacoes_de_credito",
         "verbete_420_depositos_de_poupanca")]

## -----------------------------------------------------------------------------
pe <- estban_read(f, uf = "PE")
table(pe$municipio)

## -----------------------------------------------------------------------------
v <- estban_verbetes()
v[v$code %in% c(160, 162, 163, 420, 432), c("name", "codes", "side")]
v[v$n_codes > 1, c("codes", "n_codes")]

## ----eval = FALSE-------------------------------------------------------------
# options(estbanr.cache_dir = "~/data/estban")   # persistent across sessions
# 
# x <- estban_fetch(202301, 202312, uf = "PE")
# table(x$ref)

## -----------------------------------------------------------------------------
m <- estban_by_municipality(x, impute = FALSE)
m[, c("uf", "municipio", "ref", "verbete_160_operacoes_de_credito")]

## -----------------------------------------------------------------------------
head(estban_by_municipality(x, impute = FALSE, long = TRUE))

