This function reads a DHS recode dataset from the zipped flat file dataset.

read_dhs_flat(zfile, all_lower = TRUE, meta_source = NULL)

Arguments

zfile

Path to `.zip` file containing flat file dataset, usually ending in filename `XXXXXXFL.zip`

all_lower

Logical indicating whether all value labels should be lower case. Default to `TRUE`.

meta_source

character string indicating metadata source file for data dictionary. Default NULL first tried to use .DCF and then .SPS if not found.

Value

A data frame. Value labels for each variable are stored as the `labelled` class from `haven`.

See also

labelled, read_dhs_dta.

For more information on the DHS filetypes and contents of distributed dataset .ZIP files, see https://dhsprogram.com/data/File-Types-and-Names.cfm#CP_JUMP_10334.

Examples

mrfl_zip <- tempfile() download.file( paste0( "https://dhsprogram.com/customcf/legacy/data/sample_download_dataset.cfm?", "Filename=ZZMR61FL.ZIP&Tp=1&Ctry_Code=zz&survey_id=0&doctype=dhs"), mrfl_zip,mode="wb" ) mr <- rdhs:::read_dhs_flat(mrfl_zip) attr(mr$mv213, "label")
#> [1] "Partner currently pregnant"
class(mr$mv213)
#> [1] "haven_labelled"
head(mr$mv213)
#> <Labelled integer>: Partner currently pregnant #> [1] NA 0 0 NA 0 NA #> #> Labels: #> value label #> 0 no #> 1 yes #> 8 unsure #> 9 missing
table(mr$mv213)
#> #> 0 1 8 9 #> 1766 239 57 13
table(haven::as_factor(mr$mv213))
#> #> no yes unsure missing #> 1766 239 57 13