Read Fusion Output Files From Disk
read_fsd.Rdread_fsd() efficiently loads microdata fusion outputs (.fsd files) or standard Fast
Storage (.fst) datasets into memory. Because fusion files can become extremely large
when generating multiple implicates, read_fsd() leverages partial reading capabilities
to load only the specific rows, columns, or implicates needed, drastically reducing memory
footprint and processing time.
Usage
read_fsd(
path,
columns = NULL,
M = 1,
df = NULL,
cores = max(1, parallel::detectCores(logical = FALSE) - 1)
)Arguments
- path
Character. Path to a valid
.fsdor.fstfile on disk, typically created by callingfusewith thefsdargument specified.- columns
Character vector. Specific column names to read from disk. The default (
NULL) loads all available columns in the dataset.- M
Numeric or Integer. The maximum number of implicates to read (e.g.,
M = 5loads implicates1through5). SetM = Infto load all implicates available in the file. Default is1. Ignored if the target dataset does not contain anMcolumn.- df
Data frame or data.table. Optional filtering subset. If provided, only rows in the file matching the combination of key values in
dfwill be returned. Default isNULL.- cores
Integer. Number of CPU threads to assign to
fstfor multi-threaded decompression. Defaults to available logical cores minus one (minimum 1).
Value
A data.table containing the requested columns and rows.
Original data.table key attributes are automatically preserved if present in the source file.
Details
The .fsd format (Fusion Data file) is functionally identical to the high-performance binary
format supplied by the fst package, optimized for fast random access and compression.
Subsetting Mechanics:
Implicate Filtering: When the dataset contains multiple implicates (identified by column
M),read_fsd()calculates contiguous row indices corresponding toM <= max_Mbefore reading, preventing unnecessary disk I/O for unused implicates.Row Subsetting (
df): If a matching datasetdfis provided:
Examples
if (FALSE) { # \dontrun{
# Build a fusion model using RECS microdata
fusion.vars <- c("electricity", "natural_gas", "aircon")
predictor.vars <- names(recs)[2:12]
fsn.path <- train(data = recs, y = fusion.vars, x = predictor.vars)
# Write fusion implicates directly to disk during fusion
recipient <- recs[predictor.vars]
fsd_file <- file.path(tempdir(), "results.fsd")
fuse(data = recipient, fsn = fsn.path, M = 3, fsd = fsd_file)
# Read only the first implicate (M = 1) for all variables
sim_m1 <- read_fsd(path = fsd_file, M = 1)
head(sim_m1)
# Read specific columns across all 3 implicates
sim_sub <- read_fsd(
path = fsd_file,
columns = c("M", "electricity"),
M = 3
)
head(sim_sub)
} # }