The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.

An end-to-end ObrasGov workflow

library(obrasgovr)

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.

1. Define the query explicitly

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] 5

Before sending the request, confirm that the chosen filters exist:

available_project_filters <- list_filters("projects")$filter
requested_filters <- c("uf_principal", "situacao")

all(requested_filters %in% available_project_filters)
#> [1] TRUE

2. Retrieve the project table

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.

project_metadata <- result_metadata(projects)

project_metadata[c(
  "total_items",
  "total_pages",
  "pages_retrieved",
  "retrieved_at"
)]

3. Choose project identifiers

Related endpoint queries should be limited to the projects needed for the analysis. The example below uses the first ten unique identifiers.

project_ids <- projects |>
  dplyr::distinct(id_projeto_investimento) |>
  dplyr::slice_head(n = 10) |>
  dplyr::pull(id_projeto_investimento)

project_ids

6. Preserve provenance

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.

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.