From 56fe7c184a24879d352330443c0087b3b1e0ca93 Mon Sep 17 00:00:00 2001 From: Doug Sanders Date: Tue, 1 Mar 2022 17:14:06 -0800 Subject: [PATCH 1/2] made QC additions, corrections and changes per issues #199 and #201 --- R/AE_Assess.R | 4 +++- R/AE_Map_Raw.R | 7 ++++--- man/AE_Map_Raw.Rd | 4 ++-- tests/testthat/test_AE_Assess.R | 24 +++++++++++------------ tests/testthat/test_AE_Map_Raw.R | 33 +++++++++++++++++++++++--------- tests/testthat/test_IE_Map_Raw.R | 1 - 6 files changed, 44 insertions(+), 29 deletions(-) diff --git a/R/AE_Assess.R b/R/AE_Assess.R index 11c22d94e..74d9040f9 100644 --- a/R/AE_Assess.R +++ b/R/AE_Assess.R @@ -13,6 +13,7 @@ #' - `SiteID` - Site ID #' - `Count` - Number of Adverse Events #' - `Exposure` - Number of days of exposure +#' - `Rate` - Rate of Exposure (Count / Exposure) #' #' The Assessment #' - \code{\link{Transform_EventCount}} creates `dfTransformed`. @@ -47,7 +48,8 @@ AE_Assess <- function( dfInput, vThreshold=NULL, cLabel="", cMethod="poisson",bD "cLabel is not character" = is.character(cLabel), "cMethod is not 'poisson' or 'wilcoxon'" = cMethod %in% c("poisson","wilcoxon"), "bDataList is not logical" = is.logical(bDataList), - "One or more of these columns: SubjectID, SiteID, Count, Exposure, and Rate not found in dfInput"=all(c("SubjectID","SiteID", "Count","Exposure", "Rate") %in% names(dfInput)) + "One or more of these columns: SubjectID, SiteID, Count, Exposure, and Rate not found in dfInput"=all(c("SubjectID","SiteID", "Count","Exposure", "Rate") %in% names(dfInput)), + "cMethod must be length 1" = length(cMethod) == 1 ) lAssess <- list() lAssess$dfInput <- dfInput diff --git a/R/AE_Map_Raw.R b/R/AE_Map_Raw.R index bacd1ce7a..23fbbf696 100644 --- a/R/AE_Map_Raw.R +++ b/R/AE_Map_Raw.R @@ -20,8 +20,8 @@ #' #' Note that the function can generate data summaries for specific types of AEs, but passing filtered ADAE data to dfADAE. #' -#' @param dfAE AE dataset with columns SUBJID and rows for each AE record -#' @param dfRDSL Subject-level Raw Data (RDSL) required columns: SubjectID, SiteID, value specified in strExposureCol +#' @param dfAE AE dataset with required column SUBJID and rows for each AE record +#' @param dfRDSL Subject-level Raw Data (RDSL) with required columns: SubjectID, SiteID, value specified in strExposureCol #' @param strExposureCol Name of exposure column. 'TimeOnTreatment' by default #' #' @return Data frame with one record per person data frame with columns: SubjectID, SiteID, Count (number of AEs), Exposure (Time on Treatment in Days), Rate (AE/Day) @@ -40,7 +40,8 @@ AE_Map_Raw <- function( dfAE, dfRDSL, strExposureCol="TimeOnTreatment"){ "SUBJID column not found in dfAE"="SUBJID" %in% names(dfAE), "strExposureCol is not character"=is.character(strExposureCol), "SubjectID, SiteID and strExposureCol columns not found in dfRDSL"=all(c("SubjectID","SiteID",strExposureCol) %in% names(dfRDSL)), - "NAs found in Subject ID column of dfAE" = all(!is.na(dfAE$SUBJID)) + "NAs found in SUBJID column of dfAE" = all(!is.na(dfAE$SUBJID)), + "NAs found in Subject ID column of dfRDSL" = all(!is.na(dfRDSL$SubjectID)) ) dfInput <- dfRDSL %>% diff --git a/man/AE_Map_Raw.Rd b/man/AE_Map_Raw.Rd index 27f1858d4..e2a4b41b5 100644 --- a/man/AE_Map_Raw.Rd +++ b/man/AE_Map_Raw.Rd @@ -7,9 +7,9 @@ AE_Map_Raw(dfAE, dfRDSL, strExposureCol = "TimeOnTreatment") } \arguments{ -\item{dfAE}{AE dataset with columns SUBJID and rows for each AE record} +\item{dfAE}{AE dataset with required column SUBJID and rows for each AE record} -\item{dfRDSL}{Subject-level Raw Data (RDSL) required columns: SubjectID, SiteID, value specified in strExposureCol} +\item{dfRDSL}{Subject-level Raw Data (RDSL) with required columns: SubjectID, SiteID, value specified in strExposureCol} \item{strExposureCol}{Name of exposure column. 'TimeOnTreatment' by default} } diff --git a/tests/testthat/test_AE_Assess.R b/tests/testthat/test_AE_Assess.R index 06e27c6ae..2b866a05c 100644 --- a/tests/testthat/test_AE_Assess.R +++ b/tests/testthat/test_AE_Assess.R @@ -22,19 +22,17 @@ test_that("incorrect inputs throw errors",{ expect_error(AE_Assess(ae_input, cLabel=123)) expect_error(AE_Assess(ae_input, cMethod="abacus")) expect_error(AE_Assess(ae_input, bDataList="Yes")) + expect_error(AE_Assess(ae_input %>% select(-SubjectID))) + expect_error(AE_Assess(ae_input %>% select(-SiteID))) + expect_error(AE_Assess(ae_input %>% select(-Count))) + expect_error(AE_Assess(ae_input %>% select(-Exposure))) + expect_error(AE_Assess(ae_input %>% select(-Rate))) + expect_error(AE_Assess(ae_input, cMethod=c("wilcoxon", "poisson"))) }) -test_that("incorrect inputs throw errors",{ - expect_error(AE_Assess(ae_input %>% select(-SubjectID))) - expect_error(AE_Assess(ae_input %>% select(-SiteID))) - expect_error(AE_Assess(ae_input %>% select(-Count))) - expect_error(AE_Assess(ae_input %>% select(-Exposure))) - expect_error(AE_Assess(ae_input %>% select(-Rate))) -}) - -ae_list <- AE_Assess(ae_input, bDataList=TRUE) -expect_true(is.list(ae_list)) -expect_equal(names(ae_list),c('dfInput','dfTransformed','dfAnalyzed','dfFlagged','dfSummary')) - - +test_that("Summary created when bDataList = FALSE has correct structure",{ + ae_summary <- AE_Assess(ae_input, bDataList=FALSE) + expect_equal(length(unique(ae_summary$SiteID)) , length(ae_summary$SiteID)) + expect_equal(names(ae_summary),c( "Assessment", "Label" , "SiteID" , "N" , "PValue" , "Flag")) +}) \ No newline at end of file diff --git a/tests/testthat/test_AE_Map_Raw.R b/tests/testthat/test_AE_Map_Raw.R index c2a02c2dd..a23f0c30c 100644 --- a/tests/testthat/test_AE_Map_Raw.R +++ b/tests/testthat/test_AE_Map_Raw.R @@ -13,6 +13,10 @@ test_that("incorrect inputs throw errors",{ expect_error(AE_Map_Raw("Hi","Mom")) }) +test_that("invalid strExposureCol throws error",{ + expect_error( AE_Map_Raw(dfAE = clindata::raw_ae, dfRDSL = clindata::rawplus_rdsl, strExposureCol= "Bad_Name" )) +}) + test_that("error given if required column not found",{ expect_error( @@ -119,7 +123,7 @@ test_that("NA values in input data are handled",{ dfExposure3<-tibble::tribble( ~SubjectID, ~SiteID, ~TimeOnTreatment, - NA, 1, 10, + 1, 1, 10, 2, 1, NA, 3, NA, 30, 4, 2, 50 @@ -128,7 +132,7 @@ test_that("NA values in input data are handled",{ dfInput3 <-tibble::tribble( ~SubjectID, ~SiteID, ~Count, ~Exposure,~Rate, - NA, 1, 0, 10, 0, + 1, 1, 4, 10, 0.4, 2, 1, 2, NA, NA, 3, NA, 0, 30, 0 , 4, 2, 2, 50, .04 @@ -136,22 +140,33 @@ test_that("NA values in input data are handled",{ expect_equal(dfInput3, AE_Map_Raw(dfAE = dfAE3, dfRDSL = dfExposure3)) - - - - }) -test_that("dfAE Subject NA value throws error",{ +test_that("dfAE$SUBJID NA value throws error",{ dfAE4 <- tibble::tribble(~SUBJID, 1,NA,1,1,2,2,4,4) + dfExposure4<-tibble::tribble( + ~SubjectID, ~SiteID, ~TimeOnTreatment, + 1, 1, 10, + 2, 1, 20, + 3, 3, 30, + 4, 2, 50 + ) + + + expect_error(AE_Map_Raw(dfAE = dfAE4, dfRDSL = dfExposure4)) +}) + +test_that("dfRDSL$SubjectID NA value throws error",{ + dfAE4 <- tibble::tribble(~SUBJID, 1,1,1,1,2,2,4,4) + dfExposure4<-tibble::tribble( ~SubjectID, ~SiteID, ~TimeOnTreatment, NA, 1, 10, - 2, 1, NA, - 3, NA, 30, + 2, 1, 20, + 3, 2, 30, 4, 2, 50 ) diff --git a/tests/testthat/test_IE_Map_Raw.R b/tests/testthat/test_IE_Map_Raw.R index 1f6c8abdd..b7bd7ee9a 100644 --- a/tests/testthat/test_IE_Map_Raw.R +++ b/tests/testthat/test_IE_Map_Raw.R @@ -31,7 +31,6 @@ test_that("error given if required column not found",{ clindata::rawplus_rdsl ) ) - #"INVID", "IECAT", "IETESTCD","IETEST", "IEORRES" expect_error( IE_Map_Raw( clindata::raw_ie_a2 , From ee3a8ffdb30f4bcb24ebac429afdbfbe9f8cadf1 Mon Sep 17 00:00:00 2001 From: Doug Sanders Date: Tue, 1 Mar 2022 17:14:56 -0800 Subject: [PATCH 2/2] regenerated docs --- man/AE_Assess.Rd | 1 + 1 file changed, 1 insertion(+) diff --git a/man/AE_Assess.Rd b/man/AE_Assess.Rd index e8376f526..0e920a063 100644 --- a/man/AE_Assess.Rd +++ b/man/AE_Assess.Rd @@ -41,6 +41,7 @@ The input data (\code{dfInput}) for the AE Assessment is typically created using \item \code{SiteID} - Site ID \item \code{Count} - Number of Adverse Events \item \code{Exposure} - Number of days of exposure +\item \code{Rate} - Rate of Exposure (Count / Exposure) } The Assessment