| Title: | Download and Import Traffic Crash Data from 'INFOSIGA-SP' |
|---|---|
| Description: | Provides a programmatic interface to the open data published by the Sao Paulo State Traffic Accident Information and Management System ('INFOSIGA-SP'), maintained by the Sao Paulo State Department of Motor Vehicles ('DETRAN-SP'). Functions download and import tidy data frames of traffic crash events ('sinistros'), victims ('pessoas') and vehicles ('veiculos') from 2015 onward, handling the source encoding, decimal marks, date formats and on-disk caching. See <https://infosiga.detran.sp.gov.br/> for the original data portal. |
| Authors: | Vinicius Oike [aut, cre, cph] (ORCID: <https://orcid.org/0009-0005-8015-9189>) |
| Maintainer: | Vinicius Oike <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.0 |
| Built: | 2026-10-21 06:25:43 UTC |
| Source: | https://github.com/viniciusoike/infosigasp |
Removes package-managed cache entries. By default, only canonical cleaned datasets are removed; the downloaded source archive is retained. Files outside the package's managed cache paths are never touched.
clear_infosiga_cache(processed = TRUE, source = FALSE, quiet = FALSE)clear_infosiga_cache(processed = TRUE, source = FALSE, quiet = FALSE)
processed |
Logical. Remove all canonical cleaned datasets. |
source |
Logical. Also remove the downloaded source ZIP archive. |
quiet |
Logical. Suppress the completion message. |
Invisibly, the paths that were selected for removal.
infosiga_cache_info() and read_infosiga().
temporary_cache <- tempfile("infosigasp-example-") old_options <- options(infosigasp.cache_dir = temporary_cache) clear_infosiga_cache(quiet = TRUE) options(old_options)temporary_cache <- tempfile("infosigasp-example-") old_options <- options(infosigasp.cache_dir = temporary_cache) clear_infosiga_cache(quiet = TRUE) options(old_options)
Opens the package's searchable online data dictionary. Set
source = "official" to open the INFOSIGA-SP source website instead.
dictionary_infosiga( dataset = NULL, source = c("online", "official"), open = interactive() )dictionary_infosiga( dataset = NULL, source = c("online", "official"), open = interactive() )
dataset |
Optional dataset to link to: one of |
source |
Which documentation to open. |
open |
Logical. If |
The selected URL, invisibly.
dictionary_infosiga(open = FALSE) dictionary_infosiga("sinistros", open = FALSE) dictionary_infosiga(source = "official", open = FALSE)dictionary_infosiga(open = FALSE) dictionary_infosiga("sinistros", open = FALSE) dictionary_infosiga(source = "official", open = FALSE)
Lists the source archive and canonical cleaned datasets currently stored in the package cache. Merely inspecting the cache does not create any files or directories.
infosiga_cache_info()infosiga_cache_info()
A tibble with the cache entry type, dataset, absolute path, size in MiB and modification time. Returns an empty tibble when the cache is empty.
read_infosiga() and clear_infosiga_cache().
infosiga_cache_info()infosiga_cache_info()
Downloads (if necessary) and imports one of the three INFOSIGA-SP datasets as a tidy tibble. The first interactive call asks before downloading about 120 MB to the user's local cache; subsequent calls read from disk.
read_infosiga( dataset = c("sinistros", "pessoas", "veiculos"), processing = c("clean", "typed", "raw"), standardize = NULL, refresh = FALSE, quiet = FALSE, cache = TRUE )read_infosiga( dataset = c("sinistros", "pessoas", "veiculos"), processing = c("clean", "typed", "raw"), standardize = NULL, refresh = FALSE, quiet = FALSE, cache = TRUE )
dataset |
Which dataset to import.
|
processing |
Level of processing to apply. |
standardize |
Optional character vector selecting label harmonisation:
|
refresh |
Logical. If |
quiet |
Logical. If |
cache |
Logical. If |
Source files are encoded in Latin-1 (ISO-8859-1), use ; as the field
separator, , as the decimal mark and DD/MM/YYYY dates. Every mode
decodes text to UTF-8, parses the CSV structure and row-binds the period files.
The modes differ in what happens to the fields after that tabular import.
processing = "raw" returns a lossless tabular representation: every
field is character, including dates and numbers, while empty strings,
whitespace, sentinels and malformed representations remain visible. This
is not a byte-for-byte copy because encoding is decoded and period files
are combined.
processing = "typed" parses the documented column classes. Dates become
Date, times become hms, numeric fields become integer or double,
empty fields become NA, and identifiers remain character. Category
labels, padding and explicit source sentinels otherwise remain unchanged.
processing = "clean" starts from the typed import, then trims text, maps
"NAO DISPONIVEL" to NA, orders ordinal columns, parses ano_mes_*,
converts crash-type flags to logical, converts tempo_sinistro_obito to
integer, removes a trailing ".0" from numero_logradouro, and validates
coordinate pairs against the Sao Paulo state boundary with a 2 km buffer.
Missing qtd_* counts remain NA.
Canonical clean results are cached separately from the source ZIP. Cache
entries are keyed by the source archive checksum and an internal cleaning
schema version. Obsolete entries for a dataset are removed after a new entry
is written. Standardisation is always applied in memory after loading the
canonical clean result. Use infosiga_cache_info() to inspect disk use and
clear_infosiga_cache() to remove processed entries.
Before converting a closed-domain column, the cleaning step validates its
observed values. If an ordinal column, crash-type flag or integer field
contains an unexpected representation, the entire source column is preserved
and a warning identifies the new values. This prevents upstream changes from
becoming missing values or incorrect FALSE values silently.
Label harmonisation is selective and opt-in. standardize = "municipios"
uses official IBGE municipality names keyed by cod_ibge and harmonises the
spelling of INFOSIGA administrative regions. "cores" merges case and gender
variants of basic vehicle colours, while preserving detailed liveries and
multi-tone values. "profissoes" applies consistent title case and known
missing-value markers to occupation labels. These transformations preserve
the rows and columns and never create broader analytical categories.
A small fraction of rows in the source contain data-quality issues (for
example, an unescaped ; inside a street name, or mis-encoded coordinates).
In typed and clean modes, values that cannot be parsed to their declared
column type become NA and are recorded by readr::problems(). Raw mode
preserves those field values as character. Structural CSV problems are
recorded in every mode.
Coverage, field definitions and analytical caveats are documented in the
searchable online data dictionary returned by dictionary_infosiga(). In
particular, data from 2015–2018 cover fatal crashes only, while data from
2019 onward also include non-fatal crashes and notifications.
A tibble with one row per record. The columns
keep the original INFOSIGA-SP names (in Portuguese); see the package data
dictionary via dictionary_infosiga(). The three datasets can be joined
on id_sinistro (and id_veiculo, where present).
## Not run: # Import all occurrence records, cleaned (downloads on first use) sinistros <- read_infosiga("sinistros") levels(sinistros$dia_da_semana) # Import all victims / people involved vitimas <- read_infosiga("pessoas") # Lossless tabular import: every field is character raw <- read_infosiga("sinistros", processing = "raw") # Parse documented classes without further cleaning typed <- read_infosiga("sinistros", processing = "typed") ## End(Not run) # A bundled sample (no download required) illustrates the structure: sample_path <- system.file( "extdata", "sinistros_sample.csv", package = "infosigasp" ) if (nzchar(sample_path)) head(readr::read_delim(sample_path, ";"))## Not run: # Import all occurrence records, cleaned (downloads on first use) sinistros <- read_infosiga("sinistros") levels(sinistros$dia_da_semana) # Import all victims / people involved vitimas <- read_infosiga("pessoas") # Lossless tabular import: every field is character raw <- read_infosiga("sinistros", processing = "raw") # Parse documented classes without further cleaning typed <- read_infosiga("sinistros", processing = "typed") ## End(Not run) # A bundled sample (no download required) illustrates the structure: sample_path <- system.file( "extdata", "sinistros_sample.csv", package = "infosigasp" ) if (nzchar(sample_path)) head(readr::read_delim(sample_path, ";"))