Tidy a RREO tibble by topic, reconciling layout drift across years
Source:R/rreo_tidy.R
tidy_rreo.RdFilters a long RREO tibble (typically produced by get_rreo()) down to the
rows that match a known indicator for topic (and optionally regime),
using the rules in rreo_layout(). Account labels are matched on a
year-stable, accent-folded key (Roman numerals and formula text are
stripped before comparison), so the same call returns a coherent series
across years even when SICONFI relabelled the appendix or account.
Arguments
- data
A tibble returned by
get_rreo()orget_rreo_for_state(), with at least the columnsexercicio,conta,coluna,valor.- topic
Character. Topic name (e.g.,
"previdencia"). Seerreo_layout()for the supported set.- regime
Optional character. Filter to a subset of regimes within
topic(e.g.,"rgps","rpps"). WhenNULL(default) all regimes are kept.
Value
A tibble with the matched rows, plus extra columns:
indicador: stable indicator name (e.g.,"resultado_previdenciario_rgps").regime: matched regime.coluna_padrao,coluna_ano: seerreo_normalize_columns().
Details
Currently supported topics:
"previdencia"— federal previdência (RGPS, RPPS civis, FCDF, militares inativos) for the União sphere. Anexos 04.1 / 04.2 / 04.3 / 04.4 of the RREO; the layout knows that the RGPS appendix moved from 04.3 (up to 2022) to 04.4 (2023+) and that civis/FCDF moved from 04.1 (up to 2022) to 04.2 (2023+).
Pull requests adding new topics to inst/extdata/rreo_layout.csv are
welcome.
See also
Other RREO tidy:
rreo_layout(),
rreo_normalize_columns()
Examples
if (FALSE) { # \dontrun{
library(dplyr)
rreo <- purrr::map_dfr(2019:2023, \(yr) {
get_rreo(an_exercicio = yr, nr_periodo = 6,
co_tipo_demonstrativo = "RREO",
no_anexo = rreo_layout()$no_anexo[
rreo_layout()$topic == "previdencia" &
rreo_layout()$regime == "rgps" &
yr >= rreo_layout()$first_year &
yr <= rreo_layout()$last_year
][1],
co_esfera = "U", id_ente = 1)
})
tidy_rreo(rreo, topic = "previdencia", regime = "rgps") |>
filter(coluna_padrao == "DESPESAS LIQUIDADAS ATÉ O BIMESTRE",
is.na(coluna_ano) | coluna_ano == exercicio) |>
select(exercicio, indicador, valor)
} # }