-
Notifications
You must be signed in to change notification settings - Fork 7
/
check_dm_actarm_arm.R
executable file
·48 lines (38 loc) · 1.06 KB
/
check_dm_actarm_arm.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#' @title Check DM where ARM is not equal to ACTARM
#'
#' @description This check looks for DM entries where ARM is not equal to ACTARM
#'
#' @param DM Demographics SDTM dataset with variables USUBJID, ARM, and ACTARM
#'
#' @return Boolean value for whether the check passed or failed, with 'msg'
#' attribute if the check failed
#'
#' @export
#'
#' @importFrom dplyr %>% filter select
#'
#' @author Ying Yuen
#'
#' @examples
#'
#' DM <- data.frame(USUBJID = 1:5,
#' ARM = c(letters[1:3], letters[5:6]),
#' ACTARM = letters[1:5],
#' stringsAsFactors = FALSE)
#'
#' check_dm_actarm_arm(DM)
#'
check_dm_actarm_arm <- function(DM) {
if (DM %lacks_any% c("USUBJID", "ARM", "ACTARM")) {
fail(lacks_msg(DM, c("USUBJID", "ARM", "ACTARM")))
} else {
df <- DM %>%
select("USUBJID", "ARM", "ACTARM") %>%
filter(DM[["ARM"]] != DM[["ACTARM"]])
if (nrow(df)==0) {
pass()
} else {
fail("DM has entries where ARM != ACTARM. ", df)
}
}
}