This vignette develops a reproducible workflow for answering a concrete question: which active infrastructure projects in Pernambuco are represented in ObrasGov, and what physical execution and contract records are associated with them?
API calls are shown but not executed during package builds. This keeps the vignette suitable for CRAN while leaving the examples ready to run in an interactive R session.
Keep the filter values and retrieval limits in an object. This makes the scope easy to review and store with the result.
project_query <- list(
uf_principal = "PE",
situacao = "Em execução",
page_size = 200,
all_pages = TRUE,
page_limit = 5
)
project_query
#> $uf_principal
#> [1] "PE"
#>
#> $situacao
#> [1] "Em execução"
#>
#> $page_size
#> [1] 200
#>
#> $all_pages
#> [1] TRUE
#>
#> $page_limit
#> [1] 5Before sending the request, confirm that the chosen filters exist:
Use rlang::exec() to pass a named list of arguments to
get_projects().
projects <- rlang::exec(get_projects, !!!project_query)
projects |>
dplyr::select(
id_projeto_investimento,
desc_nome,
situacao,
dt_inicial_prevista,
dt_final_prevista
)Always inspect the metadata after a limited multi-page request. If
pages_retrieved equals page_limit while
total_pages is larger, the result is intentionally
incomplete.
Related endpoint queries should be limited to the projects needed for the analysis. The example below uses the first ten unique identifiers.
Save data together with the original query, pagination metadata, package version, retrieval time, and source update timestamp.
provenance <- list(
query = project_query,
project_metadata = result_metadata(projects),
source_updated_at = get_last_update(),
package_version = utils::packageVersion("obrasgovr"),
saved_at = Sys.time()
)
saveRDS(
list(
projects = projects,
physical_execution = physical_execution,
contracts = contracts,
provenance = provenance
),
"obrasgovr-pe-workflow.rds"
)The saved object now contains both the analytical inputs and enough context to audit or repeat the retrieval later.