
Verify a categorical variable that crossed from one program to another
Source:R/categorical_guard.R
morie_transfer_verify.RdThe transfer that matters is SPSS/Stata/SAS to R or Python: the source program stores codes plus value labels, the destination is handed the codes, and the labels are re-attached in the analysis. This function takes what the source program printed for that variable (its frequency table, label = count, and optionally its code book, code = label) and refuses to continue unless the imported vector reproduces it exactly. Rotated, swapped or positionally relabelled groups fail here, on the day of the import, with the permutation named.
Usage
morie_transfer_verify(
imported,
source_counts,
code_book = NULL,
tolerance = 0,
strict = TRUE
)Arguments
- imported
The vector as it arrived: a haven-style labelled vector, plain codes (with
code_book), or already-decoded labels.- source_counts
Named numeric vector, label = count, as printed by the source program (SPSS FREQUENCIES, Stata tabulate).
- code_book
Optional named character vector, code = label, from the source program's variable view. When
importedcarries alabelsattribute the two are compared and any disagreement is an error.- tolerance
Passed to
morie_marginals_verify.- strict
When
TRUE(the default) any disagreement is an error. WhenFALSEthe result comes back withok = FALSE,reasons, andmarginals$permutationready formorie_relabel_forensics.
Value
A list with ok, decoded (a factor in code order), marginals
(the morie_marginals_verify result) and code_book_ok.