This check looks for duplicate TR records and returns a data frame. Only applies to assessments by Investigator, selected based on uppercased TREVAL = "INVESTIGATOR" or missing or TREVAL variable does not exist.
check_tr_dup(TR)
boolean value if check failed or passed with 'msg' attribute if the test failed
# example with an error
TR <- data.frame(
USUBJID = c(1,1,2,2),
TRCAT = c(1,1,2,2),
TRTESTCD = c(1,1,2,2),
TRLINKID = c(1,1,2,2),
TRDTC = c(rep("2016-01-01",2), rep("2016-06-01",2)),
TRSTRESC = c(1,1,2,2),
TRSPID = "FORMNAME-R:19/L:19XXXX",
TREVAL = "INVESTIGATOR",
stringsAsFactors = FALSE
)
check_tr_dup(TR)
#> [1] FALSE
#> attr(,"msg")
#> [1] "There are 2 duplicated TR records. "
#> attr(,"data")
#> # A tibble: 2 × 7
#> # Groups: USUBJID, TRCAT, TRTESTCD, TRLINKID, TRSPID, TRDTC, TRSTRESC [2]
#> USUBJID TRCAT TRTESTCD TRLINKID TRSPID TRDTC TRSTRESC
#> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <dbl>
#> 1 1 1 1 1 FORMNAME-R:19/L:19XXXX 2016-01-01 1
#> 2 2 2 2 2 FORMNAME-R:19/L:19XXXX 2016-06-01 2
TR1 <- TR
TR1$TRSPID <- NULL
check_tr_dup(TR1)
#> [1] FALSE
#> attr(,"msg")
#> [1] "There are 2 duplicated TR records. "
#> attr(,"data")
#> # A tibble: 2 × 6
#> # Groups: USUBJID, TRCAT, TRTESTCD, TRLINKID, TRDTC, TRSTRESC [2]
#> USUBJID TRCAT TRTESTCD TRLINKID TRDTC TRSTRESC
#> <dbl> <dbl> <dbl> <dbl> <chr> <dbl>
#> 1 1 1 1 1 2016-01-01 1
#> 2 2 2 2 2 2016-06-01 2
TR2 <- TR
TR2$TREVAL <- NULL
check_tr_dup(TR2)
#> [1] FALSE
#> attr(,"msg")
#> [1] "There are 2 duplicated TR records. "
#> attr(,"data")
#> # A tibble: 2 × 7
#> # Groups: USUBJID, TRCAT, TRTESTCD, TRLINKID, TRSPID, TRDTC, TRSTRESC [2]
#> USUBJID TRCAT TRTESTCD TRLINKID TRSPID TRDTC TRSTRESC
#> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <dbl>
#> 1 1 1 1 1 FORMNAME-R:19/L:19XXXX 2016-01-01 1
#> 2 2 2 2 2 FORMNAME-R:19/L:19XXXX 2016-06-01 2
# example with no records flagged because issues only among IRF records
TR3 <- TR
TR3$TREVAL <- "INDEPENDENT ASSESSOR"
check_tr_dup(TR3)
#> [1] TRUE
# example with required variable missing
TR4 <- TR
TR4$TRLINKID <- NULL
check_tr_dup(TR4)
#> [1] FALSE
#> attr(,"msg")
#> [1] "TR is missing both the TRLINKID and TRLNKID variables. "