microdatasus: Download and prepare DataSUS microdata
Source:R/microdatasus.R
microdatasus-package.RdProvides a reproducible workflow for DataSUS microdata: fetch_datasus()
discovers, downloads, and combines published DBC files; read_dbc() reads a
local DBC file directly, with structural and checksum validation; and the
process_*() functions interpret official TabWin DEF/CNV/DBF dictionaries
to produce period-correct values, labels, and column types.
Details
Start with fetch_datasus() and then use the processor corresponding to the
selected system, such as process_sim(), process_sinasc(), process_sih(),
process_sia(), process_cnes(), or process_sinan(). fetch_cadger()
and fetch_sigtab() also retrieve current
auxiliary tables for standalone use.
Use datasus_variables() to inspect parsed dictionary definitions and
relations, validate_datasus_schema() to compare raw DBC fields with the
selected historical definitions and processed types, and
processing_diagnostics() to retrieve unknown codes, coercion failures, and
dictionary provenance from an individual processing call.
Processing automatically reuses repeated date values and vectorizes code
padding and CNV threshold lookup. For large requests, fetch_datasus() can
process and save one file at a time with process = TRUE,
collect = FALSE, and destination. Configure microdatasus.cache_dir
for persistent dictionary reuse by processors called directly; see
datasus_cache_dir() and the performance section of process_sim().
Network access and local data
fetch_datasus() needs access to DataSUS directory listings even when DBC
files are cached. By default it warns about connection failures and retains
successful downloads; with collect = TRUE, check for NULL before passing
the result to a processor. Use stop_on_error = TRUE to abort on failures.
A direct call to a processor or dictionary helper can fail if a required
dictionary cannot be downloaded and no valid cached copy is available.
read_dbc() reads local files without Internet access. Packaged reference
tables, including tabMun, are also available offline. Saved processing
results can be reopened with readRDS(). Persistent dictionaries are reused
when valid and refresh = FALSE; see fetch_tabwin_dictionary().
References
For concepts, coverage, data flows, and caveats of each Brazilian health information system, see Saldanha (2026), Sistemas de Informação em Saúde no Brasil.
Author
Maintainer: Raphael Saldanha raphael.saldanha@fiocruz.br (ORCID)
Authors:
Raphael Saldanha raphael.saldanha@fiocruz.br (ORCID)
Other contributors:
Sidney da Silva Pereira Bissoli (DBC decompression code) [contributor, copyright holder]
Mark Adler (blast decompressor) [contributor, copyright holder]