dbc_to_csv: Convert a DATASUS DBC file directly to CSV (streaming,...

View source: R/dbcturbo.R

dbc_to_csvR Documentation

Convert a DATASUS DBC file directly to CSV (streaming, low-RAM)

Description

Decompresses a .dbc file and writes a UTF-8 CSV to disk. Records are processed in batches, so peak RAM usage is O(batch_size * record_width) regardless of file size.

Usage

dbc_to_csv(
  input_file,
  output_file,
  batch_size = 4096L,
  encoding = NULL,
  cols = NULL,
  verbose = FALSE,
  progress = NULL,
  ...
)

Arguments

input_file

Character string. Path to the source .dbc file.

output_file

Character string. Path for the output .csv file.

batch_size

Integer >= 1. Number of records per write batch. Default 4096L.

encoding

Character string or NULL. Source encoding of character fields (e.g. "CP850", "latin1"). NULL (default) assumes ASCII / UTF-8.

cols

Character vector or NULL. Names of fields to write. NULL (default) writes every field. Selection is applied by the C writer, so unselected fields are not written to the CSV.

verbose

Logical. If TRUE, prints file metrics, a progress bar, and elapsed time upon completion. Default FALSE.

progress

Function or NULL. Custom callback called after each batch with two numeric arguments: done and total (record counts). Ctrl+C is honoured between batches.

...

Optional internal arguments.

Details

The output CSV is prefixed with a UTF-8 BOM so that Microsoft Excel opens it with correct encoding without additional configuration.

Value

TRUE invisibly on success. On failure, stops with a descriptive error message.

See Also

dbc2dbf, dbc_inspect

Examples

dbc <- system.file("extdata", "sids.dbc", package = "dbcturbo")
csv <- tempfile(fileext = ".csv")
dbc_to_csv(dbc, csv)
head(utils::read.csv(csv, fileEncoding = "UTF-8"))
unlink(csv)


dbcturbo documentation built on Oct. 10, 2026, 5:08 p.m.