Last active
June 12, 2024 14:34
-
-
Save averissimo/7e8d00d5ca2eca96d9f2aaaac5ded56f to your computer and use it in GitHub Desktop.
Sanity check on join keys
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(teal.data) | |
join_keys <- join_keys() # add custom here | |
# Sanity check on join_keys vs. teal.data::default_cdisc_join_keys ------------- | |
jk2 <- default_cdisc_join_keys[names(join_keys)] | |
issues_in_join_keys <- unlist( | |
lapply( | |
setdiff(names(join_keys), "ADSL"), | |
function(ix_name) { | |
only_in_custom <- setdiff(join_keys[ix_name, ix_name], jk2[ix_name, ix_name]) | |
only_in_default <- setdiff(jk2[ix_name, ix_name], join_keys[ix_name, ix_name]) | |
output <- c() | |
if (length(jk2[ix_name, ix_name]) > 0 && length(only_in_default) + length(only_in_custom) > 0) { | |
output <- c(output, sprintf(" '%s':", ix_name)) | |
if (length(only_in_custom) > 0) { | |
output <- c(output, | |
sprintf( | |
" (%d) study data keys not present in default set: %s", | |
length(only_in_custom), | |
paste("'", only_in_custom, "'", collapse = ", ", sep = "") | |
) | |
) | |
} | |
if (length(only_in_default) > 0) { | |
output <- c(output, | |
sprintf( | |
" (%d) default keys not present in study data keys: %s", | |
length(only_in_default), | |
paste("'", only_in_default, "'", collapse = ", ", sep = "") | |
) | |
) | |
} | |
} | |
output | |
} | |
) | |
) | |
if (length(issues_in_join_keys) > 0) { | |
cat("Study data joinning keys has some differences from default set.", issues_in_join_keys, sep = "\n") | |
} | |
# end of sanity check on join_keys vs. teal.data::default_cdisc_join_keys ------ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment