@@ -627,8 +627,7 @@ test_missing_data <- function(directory = here::here(),
627
627
# detail_level <- match.arg(arg_choices)
628
628
629
629
# 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" ]]
632
631
# 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
633
632
if (" attributeList" %in% names(data_tbl )) {
634
633
data_tbl <- list (data_tbl )
@@ -650,36 +649,44 @@ test_missing_data <- function(directory = here::here(),
650
649
for (j in seq_len(ncol(dat ))) {
651
650
# look for NAs; if NAs found, look for correct missing data codes
652
651
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 ,
658
661
paste0(" " ,
659
662
" ---> {.file " ,
660
663
data_files [i ],
661
664
" } 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 ,
667
670
paste0(" " ,
668
671
" ---> {.file " ,
669
672
data_files [i ],
670
673
" } {.field " ,
671
674
names(dat )[j ],
672
675
" } contains missing data without a corresponding missing data code in metadata." ))
676
+ }
677
+ }
678
+ }
673
679
}
674
680
}
675
681
}
676
682
}
677
- }
678
683
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" ))
680
686
}
681
687
else {
682
688
# really only need to say it once per file/column combo
689
+ error_log <- unique(error_log )
683
690
msg <- error_log
684
691
names(msg ) <- rep(" " , length(msg ))
685
692
err <- paste0(" Undocumented missing data detected. Please document all missing data in metadata:\n " )
0 commit comments