datasus_list_files: List available DATASUS files

View source: R/datasus_catalog.R

datasus_list_filesR Documentation

List available DATASUS files

Description

Builds candidate file names from the internal catalog and, optionally, validates them against the DATASUS FTP.

Usage

datasus_list_files(
  source,
  file_type,
  year = NULL,
  month = NULL,
  uf = NULL,
  include_prelim = TRUE,
  check_exists = TRUE,
  timeout = 120,
  ftp_use_epsv = FALSE,
  verbose = TRUE
)

Arguments

source

Character vector of source codes.

file_type

Character vector of file type codes.

year

Integer vector of years.

month

Integer vector of months (required for monthly sources).

uf

Character vector of UF codes (required for UF-scoped sources).

include_prelim

Logical. Include preliminary data trees (default TRUE).

check_exists

Logical. Query the FTP and keep only files that exist (default TRUE). File names are matched case-insensitively and the spelling used on the FTP is returned. If an FTP directory cannot be listed (e.g. a timeout), a warning is emitted and the candidate files of that directory are kept with exists = NA. Setting to FALSE skips FTP access and returns all candidate files (with exists = NA).

timeout

Timeout in seconds for FTP requests (default 120).

ftp_use_epsv

Logical. Passed to curl (default FALSE).

verbose

Logical. Emit progress messages (default TRUE).

Details

year must be between 1979 and next year, month between 1 and 12, and uf must be one of datasus_ufs(); invalid values raise an error before any network access. For SIM "DO" and SINASC "DN", uf = NULL means all UFs.

Value

A tibble with one row per file, including its FTP URL and metadata.

Examples


tryCatch(
  datasus_list_files(
    source    = "SIHSUS",
    file_type = "RD",
    year      = 2024,
    month     = 1,
    uf        = c("PE", "PB"),
    verbose   = FALSE
  ),
  error = function(e) message("FTP unavailable: ", conditionMessage(e))
)


datasusr documentation built on Sept. 26, 2026, 1:08 a.m.