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.
obrasgovr provides an R interface to the Brazilian
federal government’s ObrasGov Open Data API. It validates filters
locally, handles HTTP failures, collects paginated results, and returns
tibbles with predictable types.
This vignette walks through the usual sequence: discover a resource, inspect its filters, make a small query, inspect the result, and retrieve related data.
Start with list_resources(). This function is entirely
local and does not contact the API.
list_resources()
#> # A tibble: 8 × 4
#> resource function_name endpoint paginated
#> <chr> <chr> <chr> <lgl>
#> 1 projects get_projects projeto-investimento TRUE
#> 2 commitments get_commitments empenho TRUE
#> 3 physical_execution get_physical_execution execucao-fisica TRUE
#> 4 contracts get_contracts contrato TRUE
#> 5 geometries get_geometries geometria TRUE
#> 6 status_history get_status_history historico-situacao-canc… TRUE
#> 7 feasibility_studies get_feasibility_studies estudo-viabilidade TRUE
#> 8 last_update get_last_update data-atualizacao FALSEThe function_name column identifies the function used to
query each resource. All main package functions use English names. The
API’s filter names, response fields, and categorical values remain in
Portuguese because they are part of the official ObrasGov contract.
Use list_filters() to see the accepted filter names and
their expected types. For example, projects can be filtered by state,
status, registration year, dates, and several other attributes.
project_filters <- list_filters("projects")
project_filters[c("filter", "type")]
#> # A tibble: 29 × 2
#> filter type
#> <chr> <chr>
#> 1 id_projeto_investimento character
#> 2 projeto_estruturante character
#> 3 desc_nome character
#> 4 nr_cep character
#> 5 desc_endereco character
#> 6 desc_projeto character
#> 7 desc_funcao_social character
#> 8 desc_meta_global character
#> 9 dt_inicial_prevista Date
#> 10 dt_final_prevista Date
#> # ℹ 19 more rowsAllowed categorical values are stored in the
allowed_values list-column. The following code retrieves
the values accepted by the situacao filter:
project_filters$allowed_values[
project_filters$filter == "situacao"
][[1]]
#> [1] "Cadastrada" "Cancelada" "Concluída" "Em execução" "Inacabada"
#> [6] "Paralisada"Dates can be supplied as Date values. The package
serializes them using the ISO YYYY-MM-DD format expected by
the API.
Begin with a narrow query and a small page_size. Network
calls are not run when this vignette is built, so installation and CRAN
checks do not depend on the external service.
projects_pe <- get_projects(
uf_principal = "PE",
situacao = "Em execução",
dt_cadastro = as.Date("2024-01-01"),
page_size = 25
)
projects_peThe returned object is a tibble. Date-like fields such as
dt_cadastro are converted to Date when every
non-missing value uses the ISO date format. Nested one-to-many
relationships are preserved as list-columns.
Every paginated result carries retrieval metadata. Check it before deciding whether more pages are required.
metadata <- result_metadata(projects_pe)
metadata$total_items
metadata$total_pages
metadata$pages_retrieved
metadata$retrieved_atThe initial request retrieves only one page. To collect more pages
safely, use all_pages = TRUE together with a finite
page_limit. See
vignette("pagination-and-nested-data") for details.
The API reports the time of its most recent data load. Store this value with the query results to identify the temporal version of the source.
The original Portuguese function names remain available as compatibility aliases. Paginated aliases retain their original pagination argument names.
New code should use get_projects(),
page_size, and all_pages.
The API does not require authentication. Three options customize transport without changing every function call:
options(
obrasgovr.base_url = "https://api-publica.obrasgov.gestao.gov.br/obras",
obrasgovr.timeout = 30,
obrasgovr.user_agent = "my-project/1.0 (contact@example.org)"
)By default, the client requests HTTP/2 over TLS, retries transient failures, and throttles requests to an average of 60 per minute. Throttling uses a token bucket, so a burst of up to 60 requests may go out before the rate settles.
vignette("pagination-and-nested-data") to collect
multiple pages and normalize list-columns.vignette("end-to-end-workflow") to build a
reproducible dataset from multiple ObrasGov resources.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.