The alepe package provides a tidy interface to the open
data API of the Legislative Assembly of the State of Pernambuco, Brazil
(ALEPE). Every
function returns a tibble with snake_case column names and parsed types,
ready for the tidyverse.
Available data
| Function | Endpoint | Contents |
|---|---|---|
alepe_representatives() |
/parlamentares |
Current state representatives |
alepe_staff() |
/servidores |
Staff roster |
alepe_positions() |
/cargos |
Staff counts per position |
alepe_departments() |
/lotacoes |
Staff counts per department |
alepe_remuneration() |
/remuneracao |
Remuneration per position |
alepe_contracts() |
/contratos |
Administrative contracts |
alepe_procurements() |
/licitacoes |
Procurement processes |
alepe_bills() |
/proposicoes/projetos |
Bills |
alepe_indications() |
/proposicoes/indicacoes |
Indications |
alepe_requests() |
/proposicoes/requerimentos |
Requests |
A first query
reps <- alepe_representatives()
reps
#> # A tibble: 49 × 2
#> nome_parlamentar partido
#> <chr> <chr>
#> 1 Abimael Santos PL
#> 2 Adalto Santos PP
#> 3 Aglailson Victor PSD
#> 4 Álvaro Porto MDB
#> 5 Antonio Coelho União
#> 6 Antônio Moraes PSD
#> 7 Cayo Albino PSB
#> 8 Claudiano Martins Filho PP
#> 9 Coronel Alberto Feitosa PL
#> 10 Dani Portela PT
#> # ℹ 39 more rowsFilters use an English vocabulary, but the original Portuguese API terms are accepted too — these are equivalent:
permanent <- alepe_staff(status = "permanent")
permanent_pt <- alepe_staff(status = "efetivo")
identical(permanent, permanent_pt)
#> [1] TRUEEm português
The same goes for the function names themselves: every endpoint function has an alias named after the endpoint it wraps, so a pipeline can stay in Portuguese from end to end.
identical(alepe_servidores(status = "efetivo"), permanent)
#> [1] TRUEalepe_parlamentares(), alepe_cargos(),
alepe_lotacoes(), alepe_remuneracao(),
alepe_contratos(), alepe_licitacoes(),
alepe_projetos(), alepe_indicacoes(),
alepe_requerimentos() and alepe_limpar_cache()
complete the set. The propositions aliases take Portuguese argument
names as well — alepe_projetos(ano = 2024). See
?alepe_aliases.
Caching
Responses are cached under
tools::R_user_dir("alepe", "cache") for six hours by
default, so repeated calls in an analysis session do not hit the API
again. Control it with:
# Change expiry (seconds)
options(alepe.cache_max_age = 24 * 3600)
# Force a fresh download for one call
alepe_staff(refresh = TRUE)
# Wipe the cache
alepe_cache_clear()Graceful failures
Following CRAN policy for internet resources, alepe
never errors on network problems. Requests are retried up to three times
with exponential backoff; if the API remains unreachable, the function
warns and returns a zero-row tibble with the documented columns, so
pipelines downstream keep working:
out <- alepe_contracts()
#> Warning: The ALEPE open data API could not be reached.
nrow(out)
#> [1] 0Warnings carry classes (alepe_error_http,
alepe_error_parse) for programmatic handling with
withCallingHandlers() or tryCatch().