Skip to content

datasusr

0.1.1Package record

Fast Access to Brazilian Public Health Data from 'DATASUS'

1packages depend
1.8Kdownloads / year
76.4%test coverage
13/13flavors OK

Overview

About

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.

Changes in 0.1.1

Robustness release following a code audit of the compiled reader and of the

download layer. No new dependencies.

Behaviour changes

  • Deleted DBF records (* flag) are dropped instead of returned as all-NA rows.
  • The cache layout now includes the release period (<cache>/<source>/<file_type>/<period>/<file_name>); existing caches re-download once.
  • timeout in datasus_download() / datasus_fetch() defaults to Inf.
  • datasus_download() gains success and error columns; datasus_fetch() gains refresh and overwrite arguments.
  • encoding, year, month and uf are validated and invalid values error.
Show all changes in 0.1.1Hide the rest of the changes in 0.1.1

DBC / DBF reader (compiled code)

  • **Malformed headers are rejected instead of read out of bounds.** The declared field widths are now validated against the record length before any data is touched (previously a corrupt file could make the parser read past the end of its buffer).
  • **Deleted records (* flag) are dropped.** They used to come back as all-NA rows. n_max now counts live records only.
  • **Much lower memory use on character-heavy files**: per-cell scratch allocations were replaced by a single reusable buffer.
  • **No native memory is leaked on error**: the file and decompression buffers are released through R_UnwindProtect() whenever an R error or interrupt unwinds out of the reader.
  • Integer fields are parsed with overflow detection; values outside R's integer range (including -2147483648, R's NA sentinel) are inferred as double or returned as NA instead of a wrong number.
  • Numeric, logical and date fields are always trimmed before parsing; trim_ws now only affects character output (with trim_ws = FALSE, padded numbers used to become NA).
  • Invalid dates such as 20240231 are now NA instead of rolling over into the next month.
  • encoding is validated: "latin1" (and the latin-1 / ISO-8859-1 aliases), "UTF-8" and "unknown" are accepted; anything else errors instead of being silently treated as Latin-1.
  • select and col_types names are matched case-insensitively against the DBF field names, and select names that match no column raise a warning instead of silently returning fewer columns.
  • A DBF whose data area is shorter than its header declares now reads the available records with a warning; a truncated plain DBF no longer fails with a misleading decompression error.
  • A very small DBC whose compressed payload is larger than its uncompressed record area is no longer mistaken for a plain DBF (the record-flag bytes are checked in addition to the file size).
  • n_max is floored to a whole number of rows.

Catalog, downloads and cache

  • **SIM/DO and SINASC/DN without uf now list all 27 UFs** (previously zero files were returned).
  • **Cache layout now includes the period**: <cache>/<source>/<file_type>/<period>/<file_name>. Final and preliminary releases of the same file (e.g. DOPE2022.dbc) used to share one path, which made datasus_download() fail with "Duplicate destfiles" or served a stale preliminary file forever. Existing caches will re-download once.
  • **Failed or interrupted downloads no longer poison the cache**: files are downloaded to a .part name and renamed only on success; partial files are removed. datasus_download() gains success and error columns and downloaded reflects the real outcome. datasus_fetch() skips failed files with a warning and errors if every download failed.
  • **datasus_fetch() prefers final over preliminary data**: when the same file (matched case-insensitively, and treating SINAN_P / ESUSNOTIFICA_P as preliminary aliases of SINAN / ESUSNOTIFICA) is available in both trees only the final copy is read, so rows are not duplicated. A final candidate that could not be confirmed on the FTP does not suppress a preliminary copy known to exist. datasus_fetch() also gains refresh and overwrite arguments (the vignette documented refresh but it was not accepted).
  • **timeout no longer caps the whole transfer.** It used to be passed to libcurl as the total time allowed per file (240 s), which aborted large files on the slow DATASUS FTP. It now defaults to Inf; stalled transfers are detected with a connect timeout and a low-speed limit instead.
  • FTP listing failures are reported with a warning and the affected files keep exists = NA, instead of being silently reported as absent.
  • datasus_build_path() no longer recycles a vector year against the SINASC path templates (which produced a warning and wrong paths).
  • SINAN_P was advertised in datasus_sources() but had no file types and could never be fetched; its file types are now registered.
  • year, month and uf are validated before any network access.
  • File names are matched against the FTP listing case-insensitively, keeping the server's spelling in the download URL.
  • datasus_download(use_cache = FALSE) without dest_dir writes to a fresh subdirectory of tempdir() instead of the working directory, and overwrite = FALSE is honoured in that mode.
  • datasus_get_territory() copes with upper-case member names inside the territorial ZIP.
  • New offline test suite (tests/testthat) covering the DBF parser with synthetic files and the catalog / cache / download logic with file:// URLs.

From NEWS.md in the release

Install

Health

CRAN checks
13OK
Slowest check: 2.6 min · r-devel-windows-x86_64
Status changes
  • OK13 OK2026-08-05
  • NOTE12 OK, 1 NOTE2026-08-01
  • OK7 OK2026-05-05
Advisories

none known

Documentation

In release 0.1.1
READMEYes · 441 wordsVignettesYes · 5 · dynamicNEWSYes · 100% structured · mentions 0.1.1Citation fileNoWebsiteYes · pkgdown
Help pages
25 (7 internal)includes a package overview page
Examples that run
63%10 run in a plain check · 6 only when donttest examples are enabled (R CMD check --as-cran)
Exported functions with examples
89%
Documented parameters
100%
Return-value docs
100%
Help pages citing references
0%

Downloads

1.8K
CRAN downloads in the past year
Rank #8,509 · ~5/day · ~154/mo
Daily download trend is not available in this view yet.
48630 days
1.1K90 days
1.8K1 year
Compare downloads with other packages →
Also on123 r2u9 autocran

Repository

1Stars
0Forks
0Open issues
0Open PRs
0Releases
19Commits
1Commit identities
19 commits · Last activity 2026-09-29 · 0% stars, 30d
Responsiveness
not measured

Stars over time

2026-07-07 · 02026-07-26 · 1
PracticesBeta

7 development-tooling and community-health practices detected across 5 families in the upstream repository

Checks run against github.com/strategicprojects/datasusr on 2026-10-21.

Continuous integration (2)
GitHub ActionsR CMD check workflow

The R CMD check workflow runs on Linux and macOS, and on R-devel

Docs source (2)
pkgdown

GitHub Pages site last deployed 2026-09-25

pkgdown site last built 2026-09-25

CRAN release process (1)
cran-comments.md
Lint, format, editor (1)
RStudio project
Show all practicesHide 1 practice
Git structural (1)
.gitattributes
How this is detected·Detection ruleset v4 (2026-10-20)
AI coding toolsBeta

This repository shows signs of AI coding tools.

  • Claude Codefirst seen on or before 2026-04-29
    Seen in the repository: CLAUDE.md
    Named in .Rbuildignore: .claude, CLAUDE.md
    Commits: at least 7 crediting it in the message
Models named in its commits
  • Claude Fable 5.13 commits · Sep 2026
  • Claude Opus 5.52 commits · Sep 2026
  • Claude Opus 4.71 commit · Apr 2026
  • Claude Opus 4.81 commit · Jun 2026
Counts are commits, not lines of code. Commits by a tool's accounts count once across all of its accounts. Commits crediting it are the largest count among its credit lines, a minimum.How this is detected·Detection ruleset v4 (updated 2026-09-27)

Dependencies

Declared dependencies
12 external dependencies (excludes base and recommended)

Installing datasusr adds 21 packages (13 with compiled code, 18 MB of source tarballs). Heaviest: stringi 11 MB, vctrs 1.0 MB, dplyr 902 KB.

Depends (1)
R >= 4.1.0
LinkingTo (0)
none
Enhances (0)
none
Reverse dependencies
1direct
0indirect
Imports 1
Depends, Imports or LinkingTo, most downloaded first

People & History

People (6)
Author, Maintainer since 0.1.0 (2026)
Author · added in 0.1.1
Author · added in 0.1.1
Contributor, Copyright holder
Author of bundled blast.c and blast.h from zlib contrib/blast
Listed in earlier versions (2)
no longer listed · 0.1.0
no longer listed · 0.1.0
Releases (2)

Pick two releases to compare their code metrics.

  • 0.1.1Latest
    record
    2026-05-04 · current release · diff ↗
  • 0.1.0
    record
    2026-05-04
  • R
    R 4.6.0 released · 2026-04-24

Package metadata

First published
2026-05-04
Total releases
2 / 1 yrs
License
MIT + file LICENSE OSI
Minimum R
≥ 4.1.0
Download size
100 KB

Cite

Cite this package

Run in R for the authors' preferred citation:

citation("datasusr")
Leite, A., Adler, M., Amorim, C., Bezerra, D., Vasconcelos, H., & Wasiliew, M. (2026). datasusr: Fast Access to Brazilian Public Health Data from 'DATASUS' (Version 0.1.1) [Computer software]. https://doi.org/10.32614/CRAN.package.datasusr

This package has no citation file, so citation() returns this entry built from DESCRIPTION.

Cite the R Observatory

For a number measured here: a download total, a coverage figure, an archival date.

APA

Balamuta, J. J. (2026). R Observatory: Metrics for datasusr version 0.1.1 [Data set]. HJJB, LLC. Data release v2026-10-23. https://doi.org/10.5281/zenodo.21843040

From data release v2026-10-23, which the citation names so these numbers can be found later. More on citing and the projects behind them.

Report a problem with this page →

Privacy choices

These apply to this browser and are stored on this device only. Nothing about your choice is sent to us.

Read the privacy policy