Skip to contents

infosigasp provides a programmatic interface to the open data published by INFOSIGA-SP, the São Paulo State Traffic Incident Information and Management System maintained by DETRAN-SP (the São Paulo State Department of Motor Vehicles).

The package downloads the official data archive, handles its quirks (Latin-1 encoding, semicolon separators, comma decimal marks, DD/MM/YYYY dates) and returns tidy tibble objects. It imports the occurrence records published by INFOSIGA-SP from 2015 onward; coverage and definitions vary over time, as described below and in ?read_infosiga.

Installation

The package is not on CRAN yet. Install it from R-universe.

install.packages("infosigasp", repos = "https://viniciusoike.r-universe.dev")

The development version lives on GitHub.

# install.packages("remotes")
remotes::install_github("viniciusoike/infosigasp")

Datasets

INFOSIGA-SP publishes three datasets: sinistros (occurrence records), pessoas (victims) and veiculos (vehicles).

Join the datasets on id_sinistro, and on id_veiculo where present. read_infosiga() imports all available years; filter ano_sinistro after import when you need a shorter period.

Usage

The first interactive call asks before downloading about 120 MB into your user cache. Canonical clean results are also cached after their first import, so later clean reads avoid CSV parsing and coordinate validation.

library(infosigasp)

# Occurrence records (confirmed crashes and notifications)
sinistros <- read_infosiga("sinistros")

# Victims / people involved
vitimas <- read_infosiga("pessoas")

# Vehicles involved
veiculos <- read_infosiga("veiculos")

Choose how much processing to apply

read_infosiga() provides three explicit processing modes.

mode result
"raw" Every field is character; empty strings, padding, sentinels and malformed representations remain visible.
"typed" Documented dates, times and numeric fields receive useful R classes, but source labels and padding remain unchanged.
"clean" The default. Adds conservative cleaning to the typed import.

Raw mode is a lossless tabular import, not a byte-for-byte copy: the package still decodes Latin-1 to UTF-8, parses the CSV structure and combines the period files.

Clean mode trims text, maps "NAO DISPONIVEL" to NA, parses ano_mes_* as first-of-month dates, orders ordinal columns, converts crash-type flags to logical, preserves missing qtd_* counts as NA, removes export-only trailing ".0" values from numero_logradouro, and validates coordinate pairs against the São Paulo state boundary with a 2 km buffer. It does not rename columns, harmonize nominal labels or drop rows.

levels(sinistros$dia_da_semana)
#> [1] "Domingo"       "Segunda-feira" "Terça-feira"   "Quarta-feira"
#> [5] "Quinta-feira"  "Sexta-feira"   "Sábado"

levels(vitimas$gravidade_lesao)
#> [1] "LEVE"  "GRAVE" "FATAL"
raw <- read_infosiga("sinistros", processing = "raw")
typed <- read_infosiga("sinistros", processing = "typed")

Use "raw" to audit the source representation, "typed" when you want useful classes without the cleaning rules, and the default "clean" mode for most analysis. Parsing issues are available in attr(x, "problems") in every mode.

Before converting a closed-domain column, clean mode checks its observed values. If it encounters a new ordinal level, flag token or integer representation, it preserves that entire column and warns instead of silently discarding values.

Standardizing category labels

Clean mode does not harmonize nominal categories beyond its documented missing-value rule. Select the harmonizations you need with standardize. For example, cor_veiculo contains duplicate basic colours because two upstream systems disagree on case and gender agreement (PRETA, Preta; BRANCA, Branco).

veiculos <- read_infosiga("veiculos", standardize = "cores")

The other options are "municipios", which uses official IBGE municipality names and harmonizes INFOSIGA administrative-region names, and "profissoes", which title-cases occupation labels. Pass a character vector to combine options, or "all" for every option applicable to the selected dataset. Detailed vehicle liveries and multi-tone colours remain unchanged; standardization never creates broader analytical groups or reshapes fields.

The getting-started vignette covers the processing modes and standardization in full. Standardization is available only with processing = "clean".

Updating the local data

DETRAN-SP updates the data monthly. Download the latest available copy and replace the one in your user cache with:

sinistros <- read_infosiga("sinistros", refresh = TRUE)

Managing the local cache

Only the canonical processing = "clean" result is stored as a processed artifact. Standardizations are applied in memory after that artifact is loaded, so they do not create additional cache files. Raw and typed imports are never stored as processed artifacts.

Inspect disk use or remove processed results with:

By default, clear_infosiga_cache() retains the downloaded source archive. Use source = TRUE to remove it too. Set cache = FALSE in read_infosiga() to bypass the processed cache for a particular call.

Data dictionary

dictionary_infosiga() opens the searchable online data dictionary. Supply a dataset name to open its section, or use source = "official" to visit the INFOSIGA-SP source website.

dictionary_infosiga()
dictionary_infosiga("sinistros")
dictionary_infosiga(source = "official")

Example

The victims dataset gives a fatality count per year.

library(dplyr)

read_infosiga("pessoas") |>
  filter(gravidade_lesao == "FATAL") |>
  count(ano_obito, name = "deaths") |>
  arrange(ano_obito)

Data source and licence

DETRAN-SP publishes the data under a Creative Commons Attribution 4.0 licence at https://infosiga.detran.sp.gov.br/. When using the data, please cite INFOSIGA-SP / DETRAN-SP as the source.

The package itself carries the MIT licence. It is not affiliated with or endorsed by DETRAN-SP or the Government of the State of São Paulo.