This check looks for duplicate treatment records in EX

check_ex_dup(EX)

Arguments

EX

Exposure SDTM dataset with variables USUBJID, EXTRT, EXDOSE, EXSTDTC, EXSTDTC. VISIT is optional.

Value

boolean value if check failed or passed with 'msg' attribute if the test failed

Author

Fang Yuan

Examples


EX <- data.frame(
 USUBJID = rep(1,2),
 EXTRT = rep(1,2),
 EXDOSE = rep(1,2),
 EXSTDTC = rep(1,2),
 EXOCCUR = "Y"
)
check_ex_dup(EX)
#> [1] FALSE
#> attr(,"msg")
#> [1] "There are 1 duplicated exposure records. "
#> attr(,"data")
#>   USUBJID EXTRT EXDOSE EXSTDTC
#> 1       1     1      1       1

EX$EXOCCUR <- NULL

check_ex_dup(EX)
#> [1] FALSE
#> attr(,"msg")
#> [1] "There are 1 duplicated exposure records. "
#> attr(,"data")
#>   USUBJID EXTRT EXDOSE EXSTDTC
#> 1       1     1      1       1

EX$EXDOSE <- NULL

check_ex_dup(EX)
#> [1] FALSE
#> attr(,"msg")
#> [1] "EX is missing the variable: EXDOSE"

# test with sample data without duplicates

EX <- data.frame(
USUBJID = 1:2,
EXTRT = 1:2,
EXDOSE = 1:2,
EXSTDTC = 1:2,
EXOCCUR = "Y"
)

check_ex_dup(EX)
#> [1] TRUE

EX = rbind(EX,EX)

check_ex_dup(EX)
#> [1] FALSE
#> attr(,"msg")
#> [1] "There are 2 duplicated exposure records. "
#> attr(,"data")
#>   USUBJID EXTRT EXDOSE EXSTDTC
#> 1       1     1      1       1
#> 2       2     2      2       2

# check non existing vars

EX$EXTRT <- NULL
EX$EXOCCUR <- NULL

check_ex_dup(EX)
#> [1] FALSE
#> attr(,"msg")
#> [1] "EX is missing the variable: EXTRT"