Skip to content

Commit e7675ca

Browse files
committed
update test_missing_data to handle file order mismatch between metadata and list.files()
1 parent 3bb7531 commit e7675ca

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

R/tabular_data_congruence.R

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -627,8 +627,7 @@ test_missing_data <- function(directory = here::here(),
627627
#detail_level <- match.arg(arg_choices)
628628

629629
# get dataTable and all children elements
630-
data_tbl <- EML::eml_get(metadata, "dataTable")
631-
data_tbl$`@context` <- NULL
630+
data_tbl <- metadata[["dataset"]][["dataTable"]]
632631
# If there's only one csv, data_tbl ends up with one less level of nesting. Re-nest it so that the rest of the code works consistently
633632
if ("attributeList" %in% names(data_tbl)) {
634633
data_tbl <- list(data_tbl)
@@ -650,36 +649,44 @@ test_missing_data <- function(directory = here::here(),
650649
for (j in seq_len(ncol(dat))) {
651650
#look for NAs; if NAs found, look for correct missing data codes
652651
if (sum(is.na(dat[,j])) > 0) {
653-
missing <- data_tbl[[i]][["attributeList"]][["attribute"]][[j]][["missingValueCode"]][["code"]]
654-
if(is.null(missing) || sum(missing != missing_types) < 1) {
655-
#file level error message output:
656-
if (detail_level == "files") {
657-
error_log <- append(error_log,
652+
for(k in 1:length(seq_along(data_tbl))){
653+
if(data_tbl[[k]][["physical"]][["objectName"]] != data_files[i]){
654+
next
655+
} else {
656+
missing <- data_tbl[[k]][["attributeList"]][["attribute"]][[j]][["missingValueCode"]][["code"]]
657+
if(is.null(missing) || sum(missing != missing_types) < 1) {
658+
#file level error message output:
659+
if (detail_level == "files") {
660+
error_log <- append(error_log,
658661
paste0(" ",
659662
"---> {.file ",
660663
data_files[i],
661664
"} contains missing data without a corresponding missing data code in metadata." ))
662-
break
663-
}
664-
#column level error message output:
665-
if (detail_level == "columns") {
666-
error_log <- append(error_log,
665+
break
666+
}
667+
#column level error message output:
668+
if (detail_level == "columns") {
669+
error_log <- append(error_log,
667670
paste0(" ",
668671
"---> {.file ",
669672
data_files[i],
670673
"} {.field ",
671674
names(dat)[j],
672675
"} contains missing data without a corresponding missing data code in metadata."))
676+
}
677+
}
678+
}
673679
}
674680
}
675681
}
676682
}
677-
}
678683
if(is.null(error_log)){
679-
cli::cli_inform(c("v" = "Missing data listed as NA is accounted for in metadata"))
684+
cli::cli_inform(c(
685+
"v" = "Missing data listed as NA is accounted for in metadata"))
680686
}
681687
else{
682688
# really only need to say it once per file/column combo
689+
error_log <- unique(error_log)
683690
msg <- error_log
684691
names(msg) <- rep(" ", length(msg))
685692
err <- paste0("Undocumented missing data detected. Please document all missing data in metadata:\n")

0 commit comments

Comments
 (0)