R/detect_control.R

Defines functions detect_control

Documented in detect_control

#' Label samples on whether they were used as controls
#'
#' @param testkit_id Testkit ID
#' @param result Value from the 'result' column of the diagnostics table
#'
#' @return A logical value : TRUE if sample was used as a control, else FALSE
#'
#' @importFrom magrittr "%>%"
detect_control <- function(testkit_id, result) {
  s_testkit_id <- stringr::str_to_upper(testkit_id)
  s_result <- stringr::str_to_lower(result)

  control_status <- ((stringr::str_detect(
    s_testkit_id,
    "BLANK|NEGATIVE|POSITIVE"
  ) &
    stringr::str_detect(
      s_testkit_id,
      "CONTROL|KNOWN"
    )) |
    stringr::str_detect(
      s_result,
      "known positive"
    ))
  return(control_status)
}
CUGBF/deidentifiedDB documentation built on Sept. 13, 2023, 6:28 a.m.