Skip to content

Commit

Permalink
improve message in check_subjid()
Browse files Browse the repository at this point in the history
closes #16
  • Loading branch information
DanChaltiel committed Feb 21, 2024
1 parent 74192a3 commit be1acd1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
19 changes: 12 additions & 7 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,28 @@ find_keyword = function(keyword, data=getOption("edc_lookup"), ignore_case=TRUE)
#' options(edc_subjid_ref=db0$SUBJID)
#' #usually, you set something like:
#' #options(edc_subjid_ref=enrolres$subjid)
#' check_subjid(db1$SUBJID)
#' check_subjid(db1$SUBJID %>% setdiff(2))
#' check_subjid(c(db1$SUBJID, 99))
#' check_subjid(db1)
#' db1 %>% dplyr::filter(SUBJID>1) %>% check_subjid()
#' check_subjid(c(db1$SUBJID, 99, 999))
check_subjid = function(x, ref=getOption("edc_subjid_ref")){
if(is.null(ref)){
cli_abort("{.arg ref} cannot be NULL in {.fun check_subjid}. See {.help EDCimport::check_subjid} to see how to set it.")
}
x_name = rlang::caller_arg(x)
if(is.data.frame(x)){
x = x %>% select(any_of(get_key_cols()$patient_id)) %>% pull()
}
ref = sort(unique(ref))
m = setdiff(ref, x) %>% sort()
if(length(m)>0) cli_warn("Missing subject ID in {.arg {rlang::caller_arg(x)}}: {.val {m}}",
class="edc_check_subjid_miss")
if(length(m) > 0){
cli_warn("Missing {length(m)} subject{?s} ID in {.arg {x_name}}: {.val {m}}",
class = "edc_check_subjid_miss")
}
m = setdiff(x, ref) %>% sort()
if(length(m)>0) cli_warn("Additional subject ID {.arg {rlang::caller_arg(x)}}: {.val {m}}",
class="edc_check_subjid_additional")
if(length(m)>0){
cli_warn("Additional {length(m)} subject{?s} ID in {.arg {x_name}}: {.val {m}}",
class="edc_check_subjid_additional")
}
invisible(NULL)
}

Expand Down
6 changes: 3 additions & 3 deletions man/check_subjid.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit be1acd1

Please sign in to comment.