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.

tidyprf

R-CMD-check CRAN status Lifecycle: experimental License: MIT

Leia em Português

tidyprf provides access, from R, to public road safety datasets made available by the Polícia Rodoviária Federal (PRF). These include data on accidents by person, accidents by occurrence, and traffic violations.

The package allows users to select the desired dataset and year, returning the data in tabular format. Files are distributed in Parquet format via GitHub Releases and stored in a local cache after the first download.

Quick example

Map fatal accidents across Brazilian states in 2024:

library(tidyprf)
library(geobr)
library(dplyr)
library(ggplot2)

fatal <- get_crashes(2024, severity = "fatal") |>
  count(uf, name = "acidentes")

read_state(year = 2020, showProgress = FALSE) |>
  left_join(fatal, by = c("abbrev_state" = "uf")) |>
  ggplot() +
  geom_sf(aes(fill = acidentes), color = "white", linewidth = 0.3) +
  scale_fill_distiller(palette = "Reds", direction = 1, name = "Accidents") +
  labs(title = "Fatal accidents by state (2024)") +
  theme_void(base_size = 13) +
  theme(plot.title = element_text(hjust = 0.5, face = "bold"))

Installation

Install the development version from GitHub:

# install.packages("remotes")
remotes::install_github("bonijoao/tidyprf")

Datasets

Dataset Function Unit Available Years
Accidents by person get_accidents() 1 row per person 2007–2026
Accidents by occurrence get_crashes() 1 row per accident 2007–2026
Traffic violations get_violations() 1 row per violation 2019–2020, 2022–2026

All three functions support filtering by:

Use info_accidents(), info_crashes(), or info_violations() to see all variable descriptions in English or Portuguese.

Cache

Parquet files are cached locally after first download:

prf_cache()               # show cached files and sizes
prf_cache_clear()         # delete all cached files
prf_years("accidents")    # available years and row counts per dataset

Data source

Raw data are published by the PRF on the Brazilian federal government open data portal. The consolidation pipeline that converts the raw CSV files into the Parquet files consumed by this package lives at bonijoao/tidyprf-dados.

License

MIT

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.