| Title: | Tidy Access to Brazilian Federal Highway Police ('PRF') Data |
|---|---|
| Description: | Download and read Brazilian Federal Highway Police ('PRF') open data on traffic accidents by person, by occurrence, and traffic violations <https://www.gov.br/prf/pt-br/acesso-a-informacao/dados-abertos/dados-abertos-da-prf>. Data are retrieved on demand as 'Parquet' files distributed via 'GitHub' releases and cached locally for reuse. |
| Authors: | João Paulo Assis Bonifácio [aut, cre] (ORCID: <https://orcid.org/0009-0009-2335-8391>), Geraldo Magela da Cruz Pereira [aut] (ORCID: <https://orcid.org/0000-0001-6280-4870>), Pedro Mambelli Fernandes [aut] |
| Maintainer: | João Paulo Assis Bonifácio <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.0 |
| Built: | 2026-09-30 19:40:32 UTC |
| Source: | https://github.com/bonijoao/tidyprf |
Bilingual (English/Portuguese) variable descriptions for all three PRF
datasets. Used internally by info_accidents(), info_crashes(), and
info_violations().
codebookcodebook
A tibble with 97 rows and 5 columns:
Dataset name: "accidents", "crashes", or "violations"
Variable name as returned by the get_*() functions
R type abbreviation (chr, int, dbl, date)
Description in English
Description in Portuguese
Compiled from the official PRF variable dictionaries published at https://www.gov.br/prf/pt-br/acesso-a-informacao/dados-abertos/dados-abertos-da-prf.
Downloads and returns accident records at the person level (one row per person involved in each accident). Files are cached after first download.
get_accidents(year, uf = NULL, br = NULL, severity = NULL)get_accidents(year, uf = NULL, br = NULL, severity = NULL)
year |
Integer or vector of integers. Year(s) to fetch (2007-2026). |
uf |
Character or NULL. State abbreviation(s), e.g. |
br |
Integer or NULL. Federal highway number(s), e.g. |
severity |
Character or NULL. |
A tibble.
## Not run: get_accidents(2023) get_accidents(2020:2023, uf = "SP", severity = "fatal") df <- get_accidents(c(2019:2021, 2023), br = 101) ## End(Not run)## Not run: get_accidents(2023) get_accidents(2020:2023, uf = "SP", severity = "fatal") df <- get_accidents(c(2019:2021, 2023), br = 101) ## End(Not run)
Downloads and returns accident records at the occurrence level (one row per accident, with aggregated person and vehicle counts). Files are cached after first download.
get_crashes(year, uf = NULL, br = NULL, severity = NULL)get_crashes(year, uf = NULL, br = NULL, severity = NULL)
year |
Integer or vector of integers. Year(s) to fetch (2007-2026). |
uf |
Character or NULL. State abbreviation(s). NULL = all. |
br |
Integer or NULL. Federal highway number(s). NULL = all. |
severity |
Character or NULL. |
A tibble.
## Not run: get_crashes(2023) get_crashes(2020:2023, uf = c("SP", "RJ")) ## End(Not run)## Not run: get_crashes(2023) get_crashes(2020:2023, uf = c("SP", "RJ")) ## End(Not run)
Downloads PRF infraction records and returns an Arrow query.
Files are 100-300 MB; use dplyr::filter() before dplyr::collect()
to avoid loading the full dataset into memory.
get_violations(year, uf = NULL, br = NULL)get_violations(year, uf = NULL, br = NULL)
year |
Integer or vector of integers. Available: 2019-2020, 2022-2026. |
uf |
Character or NULL. State of infraction ( |
br |
Integer or NULL. Federal highway number ( |
An Arrow query. Call dplyr::collect() to load into a tibble.
## Not run: # Filter before collecting to avoid loading 243 MB into RAM get_violations(2024, uf = "SP") |> dplyr::filter(cod_infracao == "55412") |> dplyr::collect() ## End(Not run)## Not run: # Filter before collecting to avoid loading 243 MB into RAM get_violations(2024, uf = "SP") |> dplyr::filter(cod_infracao == "55412") |> dplyr::collect() ## End(Not run)
Variable descriptions for get_accidents()
info_accidents(lang = "en")info_accidents(lang = "en")
lang |
|
A tibble with columns variable, type, description.
info_accidents() info_accidents(lang = "pt")info_accidents() info_accidents(lang = "pt")
Variable descriptions for get_crashes()
info_crashes(lang = "en")info_crashes(lang = "en")
lang |
|
A tibble with columns variable, type, description.
info_crashes()info_crashes()
Variable descriptions for get_violations()
info_violations(lang = "en")info_violations(lang = "en")
lang |
|
A tibble with columns variable, type, description.
info_violations(lang = "pt")info_violations(lang = "pt")
Show locally cached PRF data files
prf_cache(dataset = NULL)prf_cache(dataset = NULL)
dataset |
Character or NULL. One of |
A tibble with columns dataset, year, size_mb, cached_at.
prf_cache()prf_cache()
Delete locally cached PRF data files
prf_cache_clear(dataset = NULL, year = NULL)prf_cache_clear(dataset = NULL, year = NULL)
dataset |
Character or NULL. Dataset to clear. NULL = all. |
year |
Integer or NULL. Year(s) to clear. NULL = all years. |
Invisible NULL.
## Not run: prf_cache_clear("violations", year = 2024) prf_cache_clear() ## End(Not run)## Not run: prf_cache_clear("violations", year = 2024) prf_cache_clear() ## End(Not run)
Show years available in the PRF catalog
prf_years(dataset = NULL)prf_years(dataset = NULL)
dataset |
Character or NULL. One of |
A tibble with columns dataset, year, rows, size_mb.
## Not run: prf_years() prf_years("accidents") ## End(Not run)## Not run: prf_years() prf_years("accidents") ## End(Not run)