Skip to content

Commit

Permalink
allow edc_data_warn(col_subjid)) to be NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
DanChaltiel committed May 24, 2024
1 parent e9389cd commit 54cd2a5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
17 changes: 11 additions & 6 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ reset_manual_correction = function(){
#' @param message the message. Can use {cli} formats.
#' @param issue_n (optional) identifying row number
#' @param max_subjid max number of subject ID to show in the message
#' @param col_subjid column name for subject ID
#' @param col_subjid column name for subject ID. Set to `NULL` to ignore.
#' @param ... unused
#'
#' @return `df` invisibly
Expand All @@ -429,6 +429,7 @@ reset_manual_correction = function(){
#' tm = edc_example_mixed()
#' a = tm$long_pure %>% dplyr::filter(val1a>2)
#' edc_data_warn(a, "{.val val1} should be lesser than 2", issue_n=1)
#' edc_data_warn(a, "{.val val1} should be lesser than 2", issue_n=1, col_subjid=NULL)
#' \dontrun{
#' edc_data_stop(a, "{.val val1} should *really* be lesser than 2", issue_n=2)
#' }
Expand Down Expand Up @@ -463,12 +464,16 @@ edc_data_condition = function(df, message, issue_n, max_subjid,
if(nrow(df)>0){
if(is.null(issue_n)) issue_n = "xx"
else if(is.numeric(issue_n)) issue_n = str_pad(issue_n, width=2, pad="0")
subj = df %>% pull(any_of2(col_subjid)) %>% unique() %>% sort()
n_subj = length(subj)
subj = paste0("#", subj) %>%
cli_vec(style=list("vec_trunc"=max_subjid, "vec-trunc-style"="head"))
message = format_inline(message)
fun("Issue #{col_green(issue_n)}: {message} ({n_subj} patient{?s}: {subj})")
subj_label = ""
if(!is.null(col_subjid)){
subj = df %>% pull(any_of2(col_subjid)) %>% unique() %>% sort()
n_subj = length(subj)
subj = paste0("#", subj) %>%
cli_vec(style=list("vec_trunc"=max_subjid, "vec-trunc-style"="head"))
subj_label = format_inline(" ({n_subj} patient{?s}: {subj})")
}
fun("Issue #{col_green(issue_n)}: {message}{subj_label}")
}
invisible(df)
}
Expand Down
3 changes: 2 additions & 1 deletion man/edc_data_warn.Rd

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

0 comments on commit 54cd2a5

Please sign in to comment.