MyNixOS website logo
Description

Fast Access to Brazilian Public Health Data from 'DATASUS'.

Provides fast, in-memory reading of 'DATASUS' 'DBC' files using native 'C' code, along with a catalog of public health data sources, 'FTP' file discovery, caching downloads, and a high-level datasus_fetch() function that lists, downloads, and reads files in a single call. Bundles the 'blast' decompressor from 'zlib' contrib/blast to decode 'PKWare DCL' compressed 'DBC' files and parses 'DBF' records directly for efficient import into tibbles. See the 'DATASUS' file transfer site <https://datasus.saude.gov.br> and Adler (2003) <https://github.com/madler/zlib/tree/master/contrib/blast> for details on the underlying data and compression format.

datasusr

R-CMD-check

datasusr provides fast, in-memory reading of DATASUS .dbc files and a complete workflow for discovering, downloading, caching, and reading Brazilian public health data from the DATASUS FTP.

Looking for a broader toolkit? If your workflow goes beyond the DATASUS FTP — e.g. you also need IBGE surveys (VIGITEL, PNS, PNAD-C, POF, Censo), SISAB primary-care indicators, ANS, ANVISA, or out-of-the-box variable dictionaries and value labels — healthbR is the more complete and currently more active package, and is the recommended first choice in many cases. datasusr focuses on being a small, fast, dependency-light reader for raw DBC files plus a catalog and FTP layer. See the Comparison article for the full breakdown.

❕️ Disclaimer
This package is an independent, community-maintained tool that accesses publicly available data files from the DATASUS FTP server (ftp://ftp.datasus.gov.br). It is not affiliated with the Brazilian Ministry of Health, DATASUS, or any government entity. To maintain consistency with R package development standards, all functions use English names (e.g. datasus_fetch(), datasus_sources()). However, because the source data is produced by Brazilian government systems, parameter values use official DATASUS codes in Portuguese (e.g. source = "SIHSUS", uf = "PE"), and column names in the returned tibbles reflect the original DBC/DBF field names (e.g. uf_zi, ano_cmpt, munic_res, val_tot). For reference on the original data layouts and field descriptions, use datasus_docs_url() or see the official DATASUS documentation.

Installation

# Install from GitHub
# install.packages("remotes")
remotes::install_github("StrategicProjects/datasusr")

Quick start

library(datasusr)

# One-step: list, download, and read SIH data for Pernambuco
df <- datasus_fetch(
  source    = "SIHSUS",
  file_type = "RD",
  year      = 2024,
  month     = 1,
  uf        = "PE"
)

df

Step-by-step workflow

For more control, use the individual functions:

library(datasusr)

# 1. Explore the catalog
datasus_sources()
datasus_file_types(source = "SIHSUS")

# 2. List available files on the FTP
files <- datasus_list_files(
  source    = "SIHSUS",
  file_type = "RD",
  year      = 2024,
  month     = 1:3,
  uf        = c("PE", "PB")
)

# 3. Download (with automatic caching)
downloads <- datasus_download(files, use_cache = TRUE)

# 4. Read a DBC file into a tibble
x <- read_datasus_dbc(downloads$local_file[[1]])

# 5. Read with column selection and type control
x <- read_datasus_dbc(
  downloads$local_file[[1]],
  select     = c("uf_zi", "ano_cmpt", "dt_inter", "val_tot"),
  col_types  = c(dt_inter = "date", val_tot = "double"),
  parse_dates = TRUE
)

Cache management

Downloads are cached by default so repeated runs do not hit the DATASUS FTP:

datasus_cache_info()
datasus_cache_list()

# Prune old files
datasus_cache_prune(older_than_days = 90)

# Or clear everything
datasus_cache_clear()

You can configure the cache directory via the DATASUSR_CACHE_DIR environment variable, the datasusr.cache_dir R option, or the cache_dir argument.

Data sources

DATASUS data sources supported by datasusr

Main functions

FunctionPurpose
datasus_fetch()List + download + read in one call
read_datasus_dbc()Read .dbc / .dbf files into a tibble
datasus_sources()Browse data sources in the catalog
datasus_file_types()Browse file types by source
datasus_list_files()List candidate files (optionally validated against FTP)
datasus_download()Download files with caching support
datasus_get_territory()Download territorial reference tables (municipalities, etc.)
datasus_docs_url()Find FTP paths for documentation and data dictionaries
datasus_ftp_ls()Raw FTP directory listing
datasus_cache_*()Cache management helpers

Progress messages

All functions emit cli progress messages by default. Suppress them with verbose = FALSE.

License

MIT.

Metadata

Version

0.1.0

License

Unknown

Platforms (80)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arc-linux
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • sh4-linux
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows