@@ -760,14 +760,14 @@ mod_listings_API_docs <- list(
760760 pagination = list (" " ),
761761 intended_use_label = list (" " ),
762762 subjid_var = list (" " ),
763+ receiver_id = list (" " ),
763764 review = list (
764765 " Review-related fields" ,
765766 datasets = list (" " ),
766767 choices = list (" " ),
767768 roles = list (" " ),
768769 store_path = list (" " )
769- ),
770- receiver_id = list (" " )
770+ )
771771)
772772
773773mod_listings_API_spec <- TC $ group(
@@ -777,14 +777,13 @@ mod_listings_API_spec <- TC$group(
777777 pagination = TC $ logical () | > TC $ flag(" manual_check" , " optional" ), # manually tested by check_mod_listings
778778 intended_use_label = TC $ character () | > TC $ flag(" manual_check" , " optional" ), # manually tested by check_mod_listings
779779 subjid_var = TC $ character () | > TC $ flag(" manual_check" ), # manually tested by check_mod_listings
780+ receiver_id = TC $ character () | > TC $ flag(" manual_check" ), # manually tested by check_mod_listings
780781 review = TC $ group(
781- # TODO: functionality is a WIP, so not defining for now
782782 datasets = TC $ group(),
783783 choices = TC $ character () | > TC $ flag(" one_or_more" ),
784784 roles = TC $ character () | > TC $ flag(" one_or_more" ),
785785 store_path = TC $ character () | > TC $ flag(" optional" )
786- ) | > TC $ flag(" manual_check" , " optional" ),
787- receiver_id = TC $ character () | > TC $ flag(" manual_check" ) # manually tested by check_mod_listings
786+ ) | > TC $ flag(" manual_check" , " optional" )
788787) | > TC $ attach_docs(mod_listings_API_docs )
789788
790789dataset_info_listings <- function (dataset_names , ... ) {
@@ -800,7 +799,7 @@ check_mod_listings <- function(afmm, datasets, module_id, dataset_names,
800799 ok <- check_mod_listings_auto(
801800 afmm , datasets ,
802801 module_id , dataset_names , default_vars , pagination , intended_use_label ,
803- subjid_var , receiver_id , warn , err
802+ subjid_var , receiver_id , review , warn , err
804803 )
805804
806805 # default_vars
@@ -845,10 +844,6 @@ check_mod_listings <- function(afmm, datasets, module_id, dataset_names,
845844 msg = " `subjid_var` should be either character(1) or NULL."
846845 )
847846
848- # review
849- # TODO:
850-
851- # receiver_id
852847 CM $ assert(
853848 container = err ,
854849 cond = checkmate :: test_string(receiver_id , null.ok = TRUE ),
@@ -860,6 +855,82 @@ check_mod_listings <- function(afmm, datasets, module_id, dataset_names,
860855 receiver_id , paste(names(afmm $ module_names ), collapse = " , " )
861856 )
862857 )
858+
859+ # review
860+ local({
861+ if (is.null(review )) return (NULL )
862+ ok <- CM $ assert(
863+ container = err ,
864+ cond = (checkmate :: test_list(review , names = " unique" ) &&
865+ checkmate :: test_subset(c(" datasets" , " choices" , " roles" ), names(review ))),
866+ msg = " `review` should be a list with at least three elements: `datasets`, `choices` and `roles`"
867+ ) &&
868+ CM $ assert(
869+ container = err ,
870+ cond = (checkmate :: test_list(review [[" datasets" ]], names = " unique" ) &&
871+ checkmate :: test_subset(names(review [[" datasets" ]]), dataset_names )),
872+ msg = sprintf(
873+ " `review$datasets` should be a list and its elements should be named after the following dataset names: %s" ,
874+ paste(dataset_names , collapse = " , " )
875+ )
876+ ) &&
877+ CM $ assert(
878+ container = err ,
879+ cond = checkmate :: test_character(review [[" choices" ]], min.len = 1 , min.chars = 1 , unique = TRUE ),
880+ msg = " `review$choices` should be a non-empty character vector of unique, non-empty strings"
881+ ) &&
882+ CM $ assert(
883+ container = err ,
884+ cond = checkmate :: test_character(review [[" roles" ]], min.len = 1 , min.chars = 1 , unique = TRUE ),
885+ msg = " `review$roles` should be a non-empty character vector of unique, non-empty strings"
886+ )
887+
888+ if (! ok ) return (NULL )
889+ for (domain in names(review [[" datasets" ]])){
890+ info <- review [[" datasets" ]][[domain ]]
891+
892+ for (ds_name in names(afmm [[" data" ]])){
893+ datasets <- afmm [[" data" ]][[ds_name ]]
894+ dataset <- datasets [[domain ]]
895+
896+ CM $ assert(
897+ container = err ,
898+ cond = (checkmate :: test_list(review , names = " unique" ) &&
899+ checkmate :: test_subset(c(" id_vars" , " untracked_vars" ), names(info ))),
900+ msg = sprintf(" `review$datasets$%s` should be a list with two elements named `id_vars` and `untracked_vars`" ,
901+ domain )
902+ ) &&
903+ CM $ assert(
904+ container = err ,
905+ cond = (checkmate :: test_character(info [[" id_vars" ]], min.len = 1 , min.chars = 1 , unique = TRUE ) &&
906+ checkmate :: test_subset(info [[" id_vars" ]], names(dataset ))),
907+ msg = sprintf(
908+ paste(
909+ " `review$datasets$%s$id_vars` should be a character vector listing a subset of the columns" ,
910+ " available in dataset `%s`"
911+ ), domain , domain
912+ )
913+ ) &&
914+ CM $ assert(
915+ container = err ,
916+ cond = nrow(dataset [info [[" id_vars" ]]]) == nrow(unique(dataset [info [[" id_vars" ]]])),
917+ msg = sprintf(" `review$datasets$%s$id_vars` should identify uniquely every row of the dataset `%s`" ,
918+ domain , domain )
919+ ) &&
920+ CM $ assert(
921+ container = err ,
922+ cond = (checkmate :: test_character(info [[" untracked_vars" ]], min.chars = 1 , unique = TRUE , null.ok = TRUE ) &&
923+ checkmate :: test_subset(info [[" untracked_vars" ]], names(dataset ))),
924+ msg = sprintf(
925+ paste(
926+ " `review$datasets$%s$untracked_vars` should be a character vector listing a subset of the columns" ,
927+ " available in dataset `%s`"
928+ ), domain , domain
929+ )
930+ )
931+ }
932+ }
933+ })
863934
864935 res <- list (warnings = warn [[" messages" ]], errors = err [[" messages" ]])
865936 return (res )
0 commit comments