opendatasus_baixar: Download a resource from OpenDataSUS

View source: R/opendatasus.R

opendatasus_baixarR Documentation

Download a resource from OpenDataSUS

Description

Resolves a resource from the live portal metadata, downloads it atomically and records its origin and MD5 checksum. By default, files are reused from the package cache. A cached file is refreshed automatically when the resource update timestamp changes.

Usage

opendatasus_baixar(
  conjunto,
  recurso = NULL,
  ano = "last",
  formato = NULL,
  destino = NULL,
  cache = TRUE,
  atualizar = FALSE
)

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.

Value

The normalized local file path, with classes '"datasus_arquivo"' and '"character"'. Use [datasus_proveniencia()] to inspect its origin.

Examples


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


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