microdados_ler: Download and read raw DATASUS microdata

View source: R/microdata.R

microdados_lerR Documentation

Download and read raw DATASUS microdata

Description

Downloads the requested DBC files and reads them directly in memory using the native 'datasusr' decoder. Column selection and 'n_max' are applied during parsing, which is useful for large SIH files.

Usage

microdados_ler(
  sistema,
  tipo = NULL,
  ano,
  mes = NULL,
  uf = NULL,
  destino = NULL,
  cache = TRUE,
  atualizar = FALSE,
  preliminares = TRUE,
  verificar = TRUE,
  timeout = 240,
  colunas = NULL,
  n_max = Inf,
  normalizar = FALSE,
  juntar = TRUE,
  ...
)

Arguments

sistema

System: '"sim"', '"sinasc"' or '"sih"'.

tipo

File type returned by [microdados_catalogo()]. 'NULL' selects the default type for the system.

ano

One or more four-digit years.

mes

One or more months from 1 to 12. Required for SIH.

uf

One or more state abbreviations, two-digit IBGE codes or state names. Required for UF-scoped types.

destino

Optional destination directory. 'NULL' uses the package cache, or a session temporary directory when 'cache = FALSE'.

cache

Whether to reuse the disk cache.

atualizar

Whether to request a fresh copy of already cached files.

preliminares

Whether preliminary directories may be considered.

verificar

Whether to verify file existence on the DATASUS server.

timeout

Network timeout in seconds for file discovery.

colunas

Optional vector of original or lower-case columns to read.

n_max

Maximum number of records to read from each file.

normalizar

Whether to rename and type common fields with [datasus_padronizar()].

juntar

Whether to combine multiple files. If 'FALSE', returns a named list.

...

Additional arguments passed to [datasusr::read_datasus_dbc()].

Value

A data frame, or a named list when 'juntar = FALSE', with provenance metadata attached.

Examples


old_options <- options(
  datasus.timeout = 5,
  datasus.download_timeout = 15,
  datasus.max_tries = 1
)
try({
admissions <- microdados_ler(
  "sih",
  ano = 2024,
  mes = 1,
  uf = "AC",
  colunas = c("MUNIC_RES", "DT_INTER", "DIAG_PRINC", "VAL_TOT"),
  n_max = 1000,
  normalizar = TRUE
)
})
options(old_options)


datasus documentation built on Oct. 7, 2026, 1:07 a.m.