opendatasus_ler: Download and read tabular OpenDataSUS data

View source: R/opendatasus.R

opendatasus_lerR Documentation

Download and read tabular OpenDataSUS data

Description

Selects and downloads one CSV or JSON resource, then reads it into R. CSV delimiters are detected automatically. For very large datasets, use 'n_max' while exploring the columns, or call [opendatasus_baixar()] and use a streaming database engine.

Usage

opendatasus_ler(
  conjunto,
  recurso = NULL,
  ano = "last",
  formato = NULL,
  destino = NULL,
  cache = TRUE,
  atualizar = FALSE,
  n_max = Inf,
  colunas = NULL,
  ...
)

Arguments

conjunto

Dataset slug returned by [opendatasus_catalogo()].

recurso

Optional exact resource name or stable resource identifier.

ano

Resource year, '"last"' for the latest dated resource, or 'NULL'. Ignored when 'recurso' is supplied.

formato

Resource format. When both 'recurso' and 'formato' are 'NULL', CSV is preferred.

destino

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

cache

Whether to cache portal metadata for the duration controlled by option 'datasus.cache_ttl'.

atualizar

Whether to ignore cached metadata and query the portal again.

n_max

Maximum number of CSV rows to read. For JSON data, the limit is applied after parsing when the result is a data frame.

colunas

Optional character vector selecting columns while CSV files are parsed. JSON columns are selected after parsing.

...

Additional arguments passed to [readr::read_delim()] or [jsonlite::fromJSON()].

Value

The parsed resource. Attribute '"datasus_proveniencia"' records the selected resource, download time, local file and checksum.

Examples


old_options <- options(
  datasus.timeout = 5,
  datasus.download_timeout = 15,
  datasus.max_tries = 1
)
try({
dengue <- opendatasus_ler(
  "arboviroses-dengue",
  ano = 2025,
  formato = "CSV",
  n_max = 1000
)
datasus_proveniencia(dengue)
})
options(old_options)


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