Processes every file in file_manifest through the complete pipeline
(read -> match -> log -> clean -> validate) and returns the results either
merged into one data.table or as a named list of separate data.tables.
Usage
run_pipeline(
file_manifest,
config_file = "config/variable_map.yml",
log_dir = "logs/matching",
output_path = NULL,
apply_missing = FALSE,
merge = FALSE
)Arguments
- file_manifest
A
data.tableor data.frame with columns:- path
Path to each raw input file (CSV, TSV, or XLSX).
- year_tag
Integer year to attach, or
NAif already in the file.
- config_file
Path to the YAML variable map. Default
"config/variable_map.yml".- log_dir
Directory for audit logs. Default
"logs/matching".- output_path
Where to write the output. A file path when
merge = TRUE; a directory path whenmerge = FALSE. SetNULLto skip writing entirely.- apply_missing
Passed to
clean_dataset(). DefaultFALSE.- merge
Logical. If
TRUE, stack all cleaned datasets into one masterdata.table. IfFALSE(default), return a named list of separatedata.tables, one per input file.
Value
When
merge = TRUE: a singledata.tablewithyearas the first column.When
merge = FALSE: a named list ofdata.tables, one per file, keyed by the file's basename.
Output modes
merge = TRUE(defaultFALSE): stacks all cleaned datasets row-wise into a singledata.tableusingdata.table::rbindlist(). Missing columns across datasets are padded withNA.output_pathshould be a full file path (e.g."data/clean/master.csv").merge = FALSE: returns a named list where each element is the cleaneddata.tablefor one file, keyed by the file's basename.output_pathshould be a directory (e.g."data/clean"); one CSV per dataset is written there.
Examples
if (FALSE) { # \dontrun{
library(data.table)
manifest <- data.table(
path = c(
system.file("extdata", "survey_2022.csv", package = "cuci"),
system.file("extdata", "survey_2023.csv", package = "cuci")
),
year_tag = c(2022L, 2023L)
)
yml <- system.file("extdata", "variable_map.yml", package = "cuci")
# Return separate datasets (default)
result_list <- run_pipeline(manifest, config_file = yml, merge = FALSE)
result_list[["survey_2022.csv"]]
# Return one merged dataset
result_merged <- run_pipeline(manifest, config_file = yml, merge = TRUE,
output_path = "data/clean/master.csv")
} # }
