From f2950440d4b0ddfa172f5a2260449b85f9c27c55 Mon Sep 17 00:00:00 2001 From: Sadchla Mascary <112789549+sadchla-codes@users.noreply.github.com> Date: Thu, 12 Dec 2024 13:00:13 -0500 Subject: [PATCH 1/2] Closes #2546 Updating ABLFL to Null if not "Y" in `derive_var_base()`example (#2560) * Closes #2546 Updating ABLFL to Null if not "Y" in `derive_var_base()` example * fixing styling * fixing more styling * Updated other ABLFL so that the blanks are NA_charater_ * Fixing Styler * chore: #2546 alignment * chore: #2546 alignment is my best friend * chore: #2546 feel the align! * chore: #2546 docs * chore: #2546 moar NAs!! --------- Co-authored-by: Ben Straub Co-authored-by: Stefan Bundfuss <80953585+bundfussr@users.noreply.github.com> --- R/derive_var_base.R | 26 +++--- R/derive_var_chg.R | 6 +- R/derive_var_pchg.R | 6 +- R/derive_var_shift.R | 14 +-- R/derive_vars_computed.R | 30 +++--- man/derive_var_base.Rd | 26 +++--- man/derive_var_chg.Rd | 6 +- man/derive_var_pchg.Rd | 6 +- man/derive_var_shift.Rd | 14 +-- man/derive_vars_computed.Rd | 30 +++--- tests/testthat/test-derive_var_base.R | 104 ++++++++++----------- tests/testthat/test-derive_var_chg.R | 72 +++++++------- tests/testthat/test-derive_var_shift.R | 44 ++++----- tests/testthat/test-derive_vars_computed.R | 48 +++++----- 14 files changed, 216 insertions(+), 216 deletions(-) diff --git a/R/derive_var_base.R b/R/derive_var_base.R index 1d38923de2..b5312002d6 100644 --- a/R/derive_var_base.R +++ b/R/derive_var_base.R @@ -43,19 +43,19 @@ #' library(tibble) #' #' dataset <- tribble( -#' ~STUDYID, ~USUBJID, ~PARAMCD, ~AVAL, ~AVALC, ~AVISIT, ~ABLFL, ~ANRIND, -#' "TEST01", "PAT01", "PARAM01", 10.12, NA, "Baseline", "Y", "NORMAL", -#' "TEST01", "PAT01", "PARAM01", 9.700, NA, "Day 7", "N", "LOW", -#' "TEST01", "PAT01", "PARAM01", 15.01, NA, "Day 14", "N", "HIGH", -#' "TEST01", "PAT01", "PARAM02", 8.350, NA, "Baseline", "Y", "LOW", -#' "TEST01", "PAT01", "PARAM02", NA, NA, "Day 7", "N", NA, -#' "TEST01", "PAT01", "PARAM02", 8.350, NA, "Day 14", "N", "LOW", -#' "TEST01", "PAT01", "PARAM03", NA, "LOW", "Baseline", "Y", NA, -#' "TEST01", "PAT01", "PARAM03", NA, "LOW", "Day 7", "N", NA, -#' "TEST01", "PAT01", "PARAM03", NA, "MEDIUM", "Day 14", "N", NA, -#' "TEST01", "PAT01", "PARAM04", NA, "HIGH", "Baseline", "Y", NA, -#' "TEST01", "PAT01", "PARAM04", NA, "HIGH", "Day 7", "N", NA, -#' "TEST01", "PAT01", "PARAM04", NA, "MEDIUM", "Day 14", "N", NA +#' ~STUDYID, ~USUBJID, ~PARAMCD, ~AVAL, ~AVALC, ~AVISIT, ~ABLFL, ~ANRIND, +#' "TEST01", "PAT01", "PARAM01", 10.12, NA, "Baseline", "Y", "NORMAL", +#' "TEST01", "PAT01", "PARAM01", 9.700, NA, "Day 7", NA, "LOW", +#' "TEST01", "PAT01", "PARAM01", 15.01, NA, "Day 14", NA, "HIGH", +#' "TEST01", "PAT01", "PARAM02", 8.350, NA, "Baseline", "Y", "LOW", +#' "TEST01", "PAT01", "PARAM02", NA, NA, "Day 7", NA, NA, +#' "TEST01", "PAT01", "PARAM02", 8.350, NA, "Day 14", NA, "LOW", +#' "TEST01", "PAT01", "PARAM03", NA, "LOW", "Baseline", "Y", NA, +#' "TEST01", "PAT01", "PARAM03", NA, "LOW", "Day 7", NA, NA, +#' "TEST01", "PAT01", "PARAM03", NA, "MEDIUM", "Day 14", NA, NA, +#' "TEST01", "PAT01", "PARAM04", NA, "HIGH", "Baseline", "Y", NA, +#' "TEST01", "PAT01", "PARAM04", NA, "HIGH", "Day 7", NA, NA, +#' "TEST01", "PAT01", "PARAM04", NA, "MEDIUM", "Day 14", NA, NA #' ) #' #' ## Derive `BASE` variable from `AVAL` diff --git a/R/derive_var_chg.R b/R/derive_var_chg.R index 0d913d4437..4403cde780 100644 --- a/R/derive_var_chg.R +++ b/R/derive_var_chg.R @@ -25,10 +25,10 @@ #' advs <- tribble( #' ~USUBJID, ~PARAMCD, ~AVAL, ~ABLFL, ~BASE, #' "P01", "WEIGHT", 80, "Y", 80, -#' "P01", "WEIGHT", 80.8, "", 80, -#' "P01", "WEIGHT", 81.4, "", 80, +#' "P01", "WEIGHT", 80.8, NA, 80, +#' "P01", "WEIGHT", 81.4, NA, 80, #' "P02", "WEIGHT", 75.3, "Y", 75.3, -#' "P02", "WEIGHT", 76, "", 75.3 +#' "P02", "WEIGHT", 76, NA, 75.3 #' ) #' derive_var_chg(advs) derive_var_chg <- function(dataset) { diff --git a/R/derive_var_pchg.R b/R/derive_var_pchg.R index 03ac7e8c30..1c98e8c9a4 100644 --- a/R/derive_var_pchg.R +++ b/R/derive_var_pchg.R @@ -24,10 +24,10 @@ #' advs <- tribble( #' ~USUBJID, ~PARAMCD, ~AVAL, ~ABLFL, ~BASE, #' "P01", "WEIGHT", 80, "Y", 80, -#' "P01", "WEIGHT", 80.8, "", 80, -#' "P01", "WEIGHT", 81.4, "", 80, +#' "P01", "WEIGHT", 80.8, NA, 80, +#' "P01", "WEIGHT", 81.4, NA, 80, #' "P02", "WEIGHT", 75.3, "Y", 75.3, -#' "P02", "WEIGHT", 76, "", 75.3 +#' "P02", "WEIGHT", 76, NA, 75.3 #' ) #' derive_var_pchg(advs) derive_var_pchg <- function(dataset) { diff --git a/R/derive_var_shift.R b/R/derive_var_shift.R index 08f74ad836..0f9e87e3ce 100644 --- a/R/derive_var_shift.R +++ b/R/derive_var_shift.R @@ -37,13 +37,13 @@ #' library(tibble) #' #' data <- tribble( -#' ~USUBJID, ~PARAMCD, ~AVAL, ~ABLFL, ~BNRIND, ~ANRIND, -#' "P01", "ALB", 33, "Y", "LOW", "LOW", -#' "P01", "ALB", 38, NA, "LOW", "NORMAL", -#' "P01", "ALB", NA, NA, "LOW", NA, -#' "P02", "ALB", 37, "Y", "NORMAL", "NORMAL", -#' "P02", "ALB", 49, NA, "NORMAL", "HIGH", -#' "P02", "SODIUM", 147, "Y", "HIGH", "HIGH" +#' ~USUBJID, ~PARAMCD, ~AVAL, ~ABLFL, ~BNRIND, ~ANRIND, +#' "P01", "ALB", 33, "Y", "LOW", "LOW", +#' "P01", "ALB", 38, NA, "LOW", "NORMAL", +#' "P01", "ALB", NA, NA, "LOW", NA, +#' "P02", "ALB", 37, "Y", "NORMAL", "NORMAL", +#' "P02", "ALB", 49, NA, "NORMAL", "HIGH", +#' "P02", "SODIUM", 147, "Y", "HIGH", "HIGH" #' ) #' #' data %>% diff --git a/R/derive_vars_computed.R b/R/derive_vars_computed.R index fce7060b0e..979487468d 100644 --- a/R/derive_vars_computed.R +++ b/R/derive_vars_computed.R @@ -134,24 +134,24 @@ #' # Example 1: Derive BMIBL #' adsl <- tribble( #' ~STUDYID, ~USUBJID, ~AGE, ~AGEU, -#' "PILOT01", "01-1302", 61, "YEARS", -#' "PILOT01", "17-1344", 64, "YEARS" +#' "PILOT01", "01-1302", 61, "YEARS", +#' "PILOT01", "17-1344", 64, "YEARS" #' ) #' #' advs <- tribble( -#' ~STUDYID, ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~AVAL, ~AVALU, ~ABLFL, -#' "PILOT01", "01-1302", "HEIGHT", "Height (cm)", "SCREENING", 177.8, "cm", "Y", -#' "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "SCREENING", 81.19, "kg", "N", -#' "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "BASELINE", 82.1, "kg", "Y", -#' "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "WEEK 2", 81.19, "kg", "N", -#' "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "WEEK 4", 82.56, "kg", "N", -#' "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "WEEK 6", 80.74, "kg", "N", -#' "PILOT01", "17-1344", "HEIGHT", "Height (cm)", "SCREENING", 163.5, "cm", "Y", -#' "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "SCREENING", 58.06, "kg", "N", -#' "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "BASELINE", 58.06, "kg", "Y", -#' "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "WEEK 2", 58.97, "kg", "N", -#' "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "WEEK 4", 57.97, "kg", "N", -#' "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "WEEK 6", 58.97, "kg", "N" +#' ~STUDYID, ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~AVAL, ~AVALU, ~ABLFL, +#' "PILOT01", "01-1302", "HEIGHT", "Height (cm)", "SCREENING", 177.8, "cm", "Y", +#' "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "SCREENING", 81.19, "kg", NA, +#' "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "BASELINE", 82.1, "kg", "Y", +#' "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "WEEK 2", 81.19, "kg", NA, +#' "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "WEEK 4", 82.56, "kg", NA, +#' "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "WEEK 6", 80.74, "kg", NA, +#' "PILOT01", "17-1344", "HEIGHT", "Height (cm)", "SCREENING", 163.5, "cm", "Y", +#' "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "SCREENING", 58.06, "kg", NA, +#' "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "BASELINE", 58.06, "kg", "Y", +#' "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "WEEK 2", 58.97, "kg", NA, +#' "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "WEEK 4", 57.97, "kg", NA, +#' "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "WEEK 6", 58.97, "kg", NA #' ) #' #' derive_vars_computed( diff --git a/man/derive_var_base.Rd b/man/derive_var_base.Rd index 4d2a3d8a50..095c0927c4 100644 --- a/man/derive_var_base.Rd +++ b/man/derive_var_base.Rd @@ -53,19 +53,19 @@ multiple baseline records within \code{by_vars} an error is issued. library(tibble) dataset <- tribble( - ~STUDYID, ~USUBJID, ~PARAMCD, ~AVAL, ~AVALC, ~AVISIT, ~ABLFL, ~ANRIND, - "TEST01", "PAT01", "PARAM01", 10.12, NA, "Baseline", "Y", "NORMAL", - "TEST01", "PAT01", "PARAM01", 9.700, NA, "Day 7", "N", "LOW", - "TEST01", "PAT01", "PARAM01", 15.01, NA, "Day 14", "N", "HIGH", - "TEST01", "PAT01", "PARAM02", 8.350, NA, "Baseline", "Y", "LOW", - "TEST01", "PAT01", "PARAM02", NA, NA, "Day 7", "N", NA, - "TEST01", "PAT01", "PARAM02", 8.350, NA, "Day 14", "N", "LOW", - "TEST01", "PAT01", "PARAM03", NA, "LOW", "Baseline", "Y", NA, - "TEST01", "PAT01", "PARAM03", NA, "LOW", "Day 7", "N", NA, - "TEST01", "PAT01", "PARAM03", NA, "MEDIUM", "Day 14", "N", NA, - "TEST01", "PAT01", "PARAM04", NA, "HIGH", "Baseline", "Y", NA, - "TEST01", "PAT01", "PARAM04", NA, "HIGH", "Day 7", "N", NA, - "TEST01", "PAT01", "PARAM04", NA, "MEDIUM", "Day 14", "N", NA + ~STUDYID, ~USUBJID, ~PARAMCD, ~AVAL, ~AVALC, ~AVISIT, ~ABLFL, ~ANRIND, + "TEST01", "PAT01", "PARAM01", 10.12, NA, "Baseline", "Y", "NORMAL", + "TEST01", "PAT01", "PARAM01", 9.700, NA, "Day 7", NA, "LOW", + "TEST01", "PAT01", "PARAM01", 15.01, NA, "Day 14", NA, "HIGH", + "TEST01", "PAT01", "PARAM02", 8.350, NA, "Baseline", "Y", "LOW", + "TEST01", "PAT01", "PARAM02", NA, NA, "Day 7", NA, NA, + "TEST01", "PAT01", "PARAM02", 8.350, NA, "Day 14", NA, "LOW", + "TEST01", "PAT01", "PARAM03", NA, "LOW", "Baseline", "Y", NA, + "TEST01", "PAT01", "PARAM03", NA, "LOW", "Day 7", NA, NA, + "TEST01", "PAT01", "PARAM03", NA, "MEDIUM", "Day 14", NA, NA, + "TEST01", "PAT01", "PARAM04", NA, "HIGH", "Baseline", "Y", NA, + "TEST01", "PAT01", "PARAM04", NA, "HIGH", "Day 7", NA, NA, + "TEST01", "PAT01", "PARAM04", NA, "MEDIUM", "Day 14", NA, NA ) ## Derive `BASE` variable from `AVAL` diff --git a/man/derive_var_chg.Rd b/man/derive_var_chg.Rd index 685104511f..e8c822abc3 100644 --- a/man/derive_var_chg.Rd +++ b/man/derive_var_chg.Rd @@ -25,10 +25,10 @@ library(tibble) advs <- tribble( ~USUBJID, ~PARAMCD, ~AVAL, ~ABLFL, ~BASE, "P01", "WEIGHT", 80, "Y", 80, - "P01", "WEIGHT", 80.8, "", 80, - "P01", "WEIGHT", 81.4, "", 80, + "P01", "WEIGHT", 80.8, NA, 80, + "P01", "WEIGHT", 81.4, NA, 80, "P02", "WEIGHT", 75.3, "Y", 75.3, - "P02", "WEIGHT", 76, "", 75.3 + "P02", "WEIGHT", 76, NA, 75.3 ) derive_var_chg(advs) } diff --git a/man/derive_var_pchg.Rd b/man/derive_var_pchg.Rd index e8a9aee716..12c945f953 100644 --- a/man/derive_var_pchg.Rd +++ b/man/derive_var_pchg.Rd @@ -27,10 +27,10 @@ library(tibble) advs <- tribble( ~USUBJID, ~PARAMCD, ~AVAL, ~ABLFL, ~BASE, "P01", "WEIGHT", 80, "Y", 80, - "P01", "WEIGHT", 80.8, "", 80, - "P01", "WEIGHT", 81.4, "", 80, + "P01", "WEIGHT", 80.8, NA, 80, + "P01", "WEIGHT", 81.4, NA, 80, "P02", "WEIGHT", 75.3, "Y", 75.3, - "P02", "WEIGHT", 76, "", 75.3 + "P02", "WEIGHT", 76, NA, 75.3 ) derive_var_pchg(advs) } diff --git a/man/derive_var_shift.Rd b/man/derive_var_shift.Rd index cd8256f938..4a1e097455 100644 --- a/man/derive_var_shift.Rd +++ b/man/derive_var_shift.Rd @@ -49,13 +49,13 @@ missing value is replaced by \code{missing_value} (e.g. "NORMAL to NULL"). library(tibble) data <- tribble( - ~USUBJID, ~PARAMCD, ~AVAL, ~ABLFL, ~BNRIND, ~ANRIND, - "P01", "ALB", 33, "Y", "LOW", "LOW", - "P01", "ALB", 38, NA, "LOW", "NORMAL", - "P01", "ALB", NA, NA, "LOW", NA, - "P02", "ALB", 37, "Y", "NORMAL", "NORMAL", - "P02", "ALB", 49, NA, "NORMAL", "HIGH", - "P02", "SODIUM", 147, "Y", "HIGH", "HIGH" + ~USUBJID, ~PARAMCD, ~AVAL, ~ABLFL, ~BNRIND, ~ANRIND, + "P01", "ALB", 33, "Y", "LOW", "LOW", + "P01", "ALB", 38, NA, "LOW", "NORMAL", + "P01", "ALB", NA, NA, "LOW", NA, + "P02", "ALB", 37, "Y", "NORMAL", "NORMAL", + "P02", "ALB", 49, NA, "NORMAL", "HIGH", + "P02", "SODIUM", 147, "Y", "HIGH", "HIGH" ) data \%>\% diff --git a/man/derive_vars_computed.Rd b/man/derive_vars_computed.Rd index d2b104ab6b..4e9f042fe5 100644 --- a/man/derive_vars_computed.Rd +++ b/man/derive_vars_computed.Rd @@ -139,24 +139,24 @@ library(dplyr) # Example 1: Derive BMIBL adsl <- tribble( ~STUDYID, ~USUBJID, ~AGE, ~AGEU, - "PILOT01", "01-1302", 61, "YEARS", - "PILOT01", "17-1344", 64, "YEARS" + "PILOT01", "01-1302", 61, "YEARS", + "PILOT01", "17-1344", 64, "YEARS" ) advs <- tribble( - ~STUDYID, ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~AVAL, ~AVALU, ~ABLFL, - "PILOT01", "01-1302", "HEIGHT", "Height (cm)", "SCREENING", 177.8, "cm", "Y", - "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "SCREENING", 81.19, "kg", "N", - "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "BASELINE", 82.1, "kg", "Y", - "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "WEEK 2", 81.19, "kg", "N", - "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "WEEK 4", 82.56, "kg", "N", - "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "WEEK 6", 80.74, "kg", "N", - "PILOT01", "17-1344", "HEIGHT", "Height (cm)", "SCREENING", 163.5, "cm", "Y", - "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "SCREENING", 58.06, "kg", "N", - "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "BASELINE", 58.06, "kg", "Y", - "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "WEEK 2", 58.97, "kg", "N", - "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "WEEK 4", 57.97, "kg", "N", - "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "WEEK 6", 58.97, "kg", "N" + ~STUDYID, ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~AVAL, ~AVALU, ~ABLFL, + "PILOT01", "01-1302", "HEIGHT", "Height (cm)", "SCREENING", 177.8, "cm", "Y", + "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "SCREENING", 81.19, "kg", NA, + "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "BASELINE", 82.1, "kg", "Y", + "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "WEEK 2", 81.19, "kg", NA, + "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "WEEK 4", 82.56, "kg", NA, + "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "WEEK 6", 80.74, "kg", NA, + "PILOT01", "17-1344", "HEIGHT", "Height (cm)", "SCREENING", 163.5, "cm", "Y", + "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "SCREENING", 58.06, "kg", NA, + "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "BASELINE", 58.06, "kg", "Y", + "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "WEEK 2", 58.97, "kg", NA, + "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "WEEK 4", 57.97, "kg", NA, + "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "WEEK 6", 58.97, "kg", NA ) derive_vars_computed( diff --git a/tests/testthat/test-derive_var_base.R b/tests/testthat/test-derive_var_base.R index 5cc7131fdb..b36efb6edf 100644 --- a/tests/testthat/test-derive_var_base.R +++ b/tests/testthat/test-derive_var_base.R @@ -3,32 +3,32 @@ test_that("derive_var_base Test 1: `target` is set to `source` where `ABLFL == ' input <- tibble::tribble( ~STUDYID, ~USUBJID, ~PARAMCD, ~ASEQ, ~AVAL, ~ABLFL, ~BASETYPE, "TEST01", "PAT01", "PARAM01", 1, 10.12, "Y", "LAST", - "TEST01", "PAT01", "PARAM01", 2, 9.7, "", "LAST", - "TEST01", "PAT01", "PARAM01", 3, 15.01, "", "LAST", + "TEST01", "PAT01", "PARAM01", 2, 9.7, NA_character_, "LAST", + "TEST01", "PAT01", "PARAM01", 3, 15.01, NA_character_, "LAST", "TEST01", "PAT01", "PARAM02", 1, 8.35, "Y", "LAST", - "TEST01", "PAT01", "PARAM02", 2, NA, "", "LAST", - "TEST01", "PAT01", "PARAM02", 3, 8.35, "", "LAST", + "TEST01", "PAT01", "PARAM02", 2, NA, NA_character_, "LAST", + "TEST01", "PAT01", "PARAM02", 3, 8.35, NA_character_, "LAST", "TEST01", "PAT02", "PARAM01", 1, 29, "Y", "LAST", - "TEST01", "PAT02", "PARAM01", 2, 19.7, "", "LAST", - "TEST01", "PAT02", "PARAM01", 3, 18.01, "", "LAST", + "TEST01", "PAT02", "PARAM01", 2, 19.7, NA_character_, "LAST", + "TEST01", "PAT02", "PARAM01", 3, 18.01, NA_character_, "LAST", "TEST01", "PAT02", "PARAM02", 1, 8.9, "Y", "LAST", - "TEST01", "PAT02", "PARAM02", 2, 9, "", "LAST", - "TEST01", "PAT02", "PARAM02", 3, 5.35, "", "LAST" + "TEST01", "PAT02", "PARAM02", 2, 9, NA_character_, "LAST", + "TEST01", "PAT02", "PARAM02", 3, 5.35, NA_character_, "LAST" ) expected_output <- tibble::tribble( ~STUDYID, ~USUBJID, ~PARAMCD, ~ASEQ, ~AVAL, ~ABLFL, ~BASETYPE, ~BASE, "TEST01", "PAT01", "PARAM01", 1, 10.12, "Y", "LAST", 10.12, - "TEST01", "PAT01", "PARAM01", 2, 9.7, "", "LAST", 10.12, - "TEST01", "PAT01", "PARAM01", 3, 15.01, "", "LAST", 10.12, + "TEST01", "PAT01", "PARAM01", 2, 9.7, NA_character_, "LAST", 10.12, + "TEST01", "PAT01", "PARAM01", 3, 15.01, NA_character_, "LAST", 10.12, "TEST01", "PAT01", "PARAM02", 1, 8.35, "Y", "LAST", 8.35, - "TEST01", "PAT01", "PARAM02", 2, NA, "", "LAST", 8.35, - "TEST01", "PAT01", "PARAM02", 3, 8.35, "", "LAST", 8.35, + "TEST01", "PAT01", "PARAM02", 2, NA, NA_character_, "LAST", 8.35, + "TEST01", "PAT01", "PARAM02", 3, 8.35, NA_character_, "LAST", 8.35, "TEST01", "PAT02", "PARAM01", 1, 29, "Y", "LAST", 29, - "TEST01", "PAT02", "PARAM01", 2, 19.7, "", "LAST", 29, - "TEST01", "PAT02", "PARAM01", 3, 18.01, "", "LAST", 29, + "TEST01", "PAT02", "PARAM01", 2, 19.7, NA_character_, "LAST", 29, + "TEST01", "PAT02", "PARAM01", 3, 18.01, NA_character_, "LAST", 29, "TEST01", "PAT02", "PARAM02", 1, 8.9, "Y", "LAST", 8.9, - "TEST01", "PAT02", "PARAM02", 2, 9, "", "LAST", 8.9, - "TEST01", "PAT02", "PARAM02", 3, 5.35, "", "LAST", 8.9 + "TEST01", "PAT02", "PARAM02", 2, 9, NA_character_, "LAST", 8.9, + "TEST01", "PAT02", "PARAM02", 3, 5.35, NA_character_, "LAST", 8.9 ) actual_output <- derive_var_base( input, @@ -47,22 +47,22 @@ test_that("derive_var_base Test 1: `target` is set to `source` where `ABLFL == ' ## Test 2: `target` is set to `NA` if a baseline record is missing ---- test_that("derive_var_base Test 2: `target` is set to `NA` if a baseline record is missing", { input <- tibble::tribble( - ~STUDYID, ~USUBJID, ~PARAMCD, ~ASEQ, ~AVAL, ~ABLFL, ~BASETYPE, - "TEST01", "PAT01", "PARAM01", 1, 10.12, "Y", "LAST", - "TEST01", "PAT01", "PARAM01", 2, 9.7, "", "LAST", - "TEST01", "PAT01", "PARAM01", 3, 15.01, "", "LAST", - "TEST01", "PAT01", "PARAM02", 1, 4.9, "", "LAST", - "TEST01", "PAT01", "PARAM02", 2, 7.1, "", "LAST", - "TEST01", "PAT01", "PARAM02", 3, 8.35, "", "LAST" + ~STUDYID, ~USUBJID, ~PARAMCD, ~ASEQ, ~AVAL, ~ABLFL, ~BASETYPE, + "TEST01", "PAT01", "PARAM01", 1, 10.12, "Y", "LAST", + "TEST01", "PAT01", "PARAM01", 2, 9.7, NA_character_, "LAST", + "TEST01", "PAT01", "PARAM01", 3, 15.01, NA_character_, "LAST", + "TEST01", "PAT01", "PARAM02", 1, 4.9, NA_character_, "LAST", + "TEST01", "PAT01", "PARAM02", 2, 7.1, NA_character_, "LAST", + "TEST01", "PAT01", "PARAM02", 3, 8.35, NA_character_, "LAST" ) expected_output <- tibble::tribble( - ~STUDYID, ~USUBJID, ~PARAMCD, ~ASEQ, ~AVAL, ~ABLFL, ~BASETYPE, ~BASE, - "TEST01", "PAT01", "PARAM01", 1, 10.12, "Y", "LAST", 10.12, - "TEST01", "PAT01", "PARAM01", 2, 9.7, "", "LAST", 10.12, - "TEST01", "PAT01", "PARAM01", 3, 15.01, "", "LAST", 10.12, - "TEST01", "PAT01", "PARAM02", 1, 4.9, "", "LAST", NA, - "TEST01", "PAT01", "PARAM02", 2, 7.1, "", "LAST", NA, - "TEST01", "PAT01", "PARAM02", 3, 8.35, "", "LAST", NA + ~STUDYID, ~USUBJID, ~PARAMCD, ~ASEQ, ~AVAL, ~ABLFL, ~BASETYPE, ~BASE, + "TEST01", "PAT01", "PARAM01", 1, 10.12, "Y", "LAST", 10.12, + "TEST01", "PAT01", "PARAM01", 2, 9.7, NA_character_, "LAST", 10.12, + "TEST01", "PAT01", "PARAM01", 3, 15.01, NA_character_, "LAST", 10.12, + "TEST01", "PAT01", "PARAM02", 1, 4.9, NA_character_, "LAST", NA, + "TEST01", "PAT01", "PARAM02", 2, 7.1, NA_character_, "LAST", NA, + "TEST01", "PAT01", "PARAM02", 3, 8.35, NA_character_, "LAST", NA ) actual_output <- derive_var_base( input, @@ -81,22 +81,22 @@ test_that("derive_var_base Test 2: `target` is set to `NA` if a baseline record ## Test 3: only the `target` variable is added to the input dataset ---- test_that("derive_var_base Test 3: only the `target` variable is added to the input dataset", { input <- tibble::tribble( - ~STUDYID, ~USUBJID, ~PARAMCD, ~ASEQ, ~AVAL, ~ABLFL, ~BASETYPE, ~ANL01FL, - "TEST01", "PAT01", "PARAM01", 1, 10.12, "Y", "LAST", "Y", - "TEST01", "PAT01", "PARAM01", 2, 9.7, "", "LAST", "Y", - "TEST01", "PAT01", "PARAM01", 3, 15.01, "", "LAST", "Y", - "TEST01", "PAT01", "PARAM02", 1, 8.35, "Y", "LAST", "Y", - "TEST01", "PAT01", "PARAM02", 2, NA, "", "LAST", "Y", - "TEST01", "PAT01", "PARAM02", 3, 8.35, "", "LAST", "Y" + ~STUDYID, ~USUBJID, ~PARAMCD, ~ASEQ, ~AVAL, ~ABLFL, ~BASETYPE, ~ANL01FL, + "TEST01", "PAT01", "PARAM01", 1, 10.12, "Y", "LAST", "Y", + "TEST01", "PAT01", "PARAM01", 2, 9.7, NA_character_, "LAST", "Y", + "TEST01", "PAT01", "PARAM01", 3, 15.01, NA_character_, "LAST", "Y", + "TEST01", "PAT01", "PARAM02", 1, 8.35, "Y", "LAST", "Y", + "TEST01", "PAT01", "PARAM02", 2, NA, NA_character_, "LAST", "Y", + "TEST01", "PAT01", "PARAM02", 3, 8.35, NA_character_, "LAST", "Y" ) expected_output <- tibble::tribble( - ~STUDYID, ~USUBJID, ~PARAMCD, ~ASEQ, ~AVAL, ~ABLFL, ~BASETYPE, ~ANL01FL, ~BASE, - "TEST01", "PAT01", "PARAM01", 1, 10.12, "Y", "LAST", "Y", 10.12, - "TEST01", "PAT01", "PARAM01", 2, 9.7, "", "LAST", "Y", 10.12, - "TEST01", "PAT01", "PARAM01", 3, 15.01, "", "LAST", "Y", 10.12, - "TEST01", "PAT01", "PARAM02", 1, 8.35, "Y", "LAST", "Y", 8.35, - "TEST01", "PAT01", "PARAM02", 2, NA, "", "LAST", "Y", 8.35, - "TEST01", "PAT01", "PARAM02", 3, 8.35, "", "LAST", "Y", 8.35 + ~STUDYID, ~USUBJID, ~PARAMCD, ~ASEQ, ~AVAL, ~ABLFL, ~BASETYPE, ~ANL01FL, ~BASE, + "TEST01", "PAT01", "PARAM01", 1, 10.12, "Y", "LAST", "Y", 10.12, + "TEST01", "PAT01", "PARAM01", 2, 9.7, NA_character_, "LAST", "Y", 10.12, + "TEST01", "PAT01", "PARAM01", 3, 15.01, NA_character_, "LAST", "Y", 10.12, + "TEST01", "PAT01", "PARAM02", 1, 8.35, "Y", "LAST", "Y", 8.35, + "TEST01", "PAT01", "PARAM02", 2, NA, NA_character_, "LAST", "Y", 8.35, + "TEST01", "PAT01", "PARAM02", 3, 8.35, NA_character_, "LAST", "Y", 8.35 ) actual_output <- derive_var_base( input, @@ -115,14 +115,14 @@ test_that("derive_var_base Test 3: only the `target` variable is added to the in ## Test 4: error if multiple baseline records ---- test_that("derive_var_base Test 4: error if multiple baseline records", { input <- tibble::tribble( - ~STUDYID, ~USUBJID, ~PARAMCD, ~AVALC, ~ABLFL, ~BASETYPE, - "TEST01", "PAT01", "PARAM01", "LOW", "Y", "LAST", - "TEST01", "PAT01", "PARAM01", "MEDIUM", "Y", "LAST", - "TEST01", "PAT01", "PARAM01", "LOW", "", "LAST", - "TEST01", "PAT01", "PARAM01", "MEDIUM", "", "LAST", - "TEST01", "PAT02", "PARAM02", "HIGH", "Y", "LAST", - "TEST01", "PAT02", "PARAM02", "HIGH", "Y", "LAST", - "TEST01", "PAT02", "PARAM02", "MEDIUM", "", "LAST", + ~STUDYID, ~USUBJID, ~PARAMCD, ~AVALC, ~ABLFL, ~BASETYPE, + "TEST01", "PAT01", "PARAM01", "LOW", "Y", "LAST", + "TEST01", "PAT01", "PARAM01", "MEDIUM", "Y", "LAST", + "TEST01", "PAT01", "PARAM01", "LOW", NA_character_, "LAST", + "TEST01", "PAT01", "PARAM01", "MEDIUM", NA_character_, "LAST", + "TEST01", "PAT02", "PARAM02", "HIGH", "Y", "LAST", + "TEST01", "PAT02", "PARAM02", "HIGH", "Y", "LAST", + "TEST01", "PAT02", "PARAM02", "MEDIUM", NA_character_, "LAST", ) expect_snapshot( diff --git a/tests/testthat/test-derive_var_chg.R b/tests/testthat/test-derive_var_chg.R index 6ea2d4bd96..3a00985e67 100644 --- a/tests/testthat/test-derive_var_chg.R +++ b/tests/testthat/test-derive_var_chg.R @@ -2,32 +2,32 @@ test_that("`CHG` is calculated as `AVAL - BASE`", { input <- tibble::tribble( ~STUDYID, ~USUBJID, ~PARAMCD, ~AVAL, ~ABLFL, ~BASETYPE, ~BASE, "TEST01", "PAT01", "PARAM01", 10.12, "Y", "LAST", 10.12, - "TEST01", "PAT01", "PARAM01", 9.7, "", "LAST", 10.12, - "TEST01", "PAT01", "PARAM01", 15.01, "", "LAST", 10.12, + "TEST01", "PAT01", "PARAM01", 9.7, NA_character_, "LAST", 10.12, + "TEST01", "PAT01", "PARAM01", 15.01, NA_character_, "LAST", 10.12, "TEST01", "PAT01", "PARAM02", 8.35, "Y", "LAST", 8.35, - "TEST01", "PAT01", "PARAM02", NA, "", "LAST", 8.35, - "TEST01", "PAT01", "PARAM02", 8.35, "", "LAST", 8.35, + "TEST01", "PAT01", "PARAM02", NA, NA_character_, "LAST", 8.35, + "TEST01", "PAT01", "PARAM02", 8.35, NA_character_, "LAST", 8.35, "TEST01", "PAT02", "PARAM01", 29, "Y", "LAST", 29, - "TEST01", "PAT02", "PARAM01", 19.7, "", "LAST", 29, - "TEST01", "PAT02", "PARAM01", 18.01, "", "LAST", 29, + "TEST01", "PAT02", "PARAM01", 19.7, NA_character_, "LAST", 29, + "TEST01", "PAT02", "PARAM01", 18.01, NA_character_, "LAST", 29, "TEST01", "PAT02", "PARAM02", 8.9, "Y", "LAST", 8.9, - "TEST01", "PAT02", "PARAM02", 9, "", "LAST", 8.9, - "TEST01", "PAT02", "PARAM02", 5.35, "", "LAST", 8.9 + "TEST01", "PAT02", "PARAM02", 9, NA_character_, "LAST", 8.9, + "TEST01", "PAT02", "PARAM02", 5.35, NA_character_, "LAST", 8.9 ) expected_output <- tibble::tribble( ~STUDYID, ~USUBJID, ~PARAMCD, ~AVAL, ~ABLFL, ~BASETYPE, ~BASE, ~CHG, "TEST01", "PAT01", "PARAM01", 10.12, "Y", "LAST", 10.12, 0, - "TEST01", "PAT01", "PARAM01", 9.7, "", "LAST", 10.12, -0.42, - "TEST01", "PAT01", "PARAM01", 15.01, "", "LAST", 10.12, 4.89, + "TEST01", "PAT01", "PARAM01", 9.7, NA_character_, "LAST", 10.12, -0.42, + "TEST01", "PAT01", "PARAM01", 15.01, NA_character_, "LAST", 10.12, 4.89, "TEST01", "PAT01", "PARAM02", 8.35, "Y", "LAST", 8.35, 0, - "TEST01", "PAT01", "PARAM02", NA, "", "LAST", 8.35, NA, - "TEST01", "PAT01", "PARAM02", 8.35, "", "LAST", 8.35, 0, + "TEST01", "PAT01", "PARAM02", NA, NA_character_, "LAST", 8.35, NA, + "TEST01", "PAT01", "PARAM02", 8.35, NA_character_, "LAST", 8.35, 0, "TEST01", "PAT02", "PARAM01", 29, "Y", "LAST", 29, 0, - "TEST01", "PAT02", "PARAM01", 19.7, "", "LAST", 29, -9.3, - "TEST01", "PAT02", "PARAM01", 18.01, "", "LAST", 29, -10.99, + "TEST01", "PAT02", "PARAM01", 19.7, NA_character_, "LAST", 29, -9.3, + "TEST01", "PAT02", "PARAM01", 18.01, NA_character_, "LAST", 29, -10.99, "TEST01", "PAT02", "PARAM02", 8.9, "Y", "LAST", 8.9, 0, - "TEST01", "PAT02", "PARAM02", 9, "", "LAST", 8.9, 0.1, - "TEST01", "PAT02", "PARAM02", 5.35, "", "LAST", 8.9, -3.55 + "TEST01", "PAT02", "PARAM02", 9, NA_character_, "LAST", 8.9, 0.1, + "TEST01", "PAT02", "PARAM02", 5.35, NA_character_, "LAST", 8.9, -3.55 ) expect_equal(derive_var_chg(input)$CHG, expected_output$CHG) @@ -37,33 +37,33 @@ test_that("`PCHG` is calculated as `(AVAL - BASE) / abs(BASE) * 100`", { input <- tibble::tribble( ~STUDYID, ~USUBJID, ~PARAMCD, ~AVAL, ~ABLFL, ~BASETYPE, ~BASE, "TEST01", "PAT01", "PARAM01", -10.12, "Y", "LAST", -10.12, - "TEST01", "PAT01", "PARAM01", -9.7, "", "LAST", -10.12, - "TEST01", "PAT01", "PARAM01", -15.01, "", "LAST", -10.12, + "TEST01", "PAT01", "PARAM01", -9.7, NA_character_, "LAST", -10.12, + "TEST01", "PAT01", "PARAM01", -15.01, NA_character_, "LAST", -10.12, "TEST01", "PAT01", "PARAM02", 8.35, "Y", "LAST", 8.35, - "TEST01", "PAT01", "PARAM02", NA, "", "LAST", 8.35, - "TEST01", "PAT01", "PARAM02", 8.35, "", "LAST", 8.35, + "TEST01", "PAT01", "PARAM02", NA, NA_character_, "LAST", 8.35, + "TEST01", "PAT01", "PARAM02", 8.35, NA_character_, "LAST", 8.35, "TEST01", "PAT02", "PARAM01", 29, "Y", "LAST", 29, - "TEST01", "PAT02", "PARAM01", 19.7, "", "LAST", 29, - "TEST01", "PAT02", "PARAM01", 18.01, "", "LAST", 29, + "TEST01", "PAT02", "PARAM01", 19.7, NA_character_, "LAST", 29, + "TEST01", "PAT02", "PARAM01", 18.01, NA_character_, "LAST", 29, "TEST01", "PAT02", "PARAM02", 8.9, "Y", "LAST", 8.9, - "TEST01", "PAT02", "PARAM02", 9, "", "LAST", 8.9, - "TEST01", "PAT02", "PARAM02", 5.35, "", "LAST", 8.9 + "TEST01", "PAT02", "PARAM02", 9, NA_character_, "LAST", 8.9, + "TEST01", "PAT02", "PARAM02", 5.35, NA_character_, "LAST", 8.9 ) expected_output <- tibble::tribble( ~STUDYID, ~USUBJID, ~PARAMCD, ~AVAL, ~ABLFL, ~BASETYPE, ~BASE, ~PCHG, "TEST01", "PAT01", "PARAM01", -10.12, "Y", "LAST", -10.12, 0, - "TEST01", "PAT01", "PARAM01", -9.7, "", "LAST", -10.12, 4.150198, - "TEST01", "PAT01", "PARAM01", -15.01, "", "LAST", -10.12, -48.32016, + "TEST01", "PAT01", "PARAM01", -9.7, NA_character_, "LAST", -10.12, 4.150198, + "TEST01", "PAT01", "PARAM01", -15.01, NA_character_, "LAST", -10.12, -48.32016, "TEST01", "PAT01", "PARAM02", 8.35, "Y", "LAST", 8.35, 0, - "TEST01", "PAT01", "PARAM02", NA, "", "LAST", 8.35, NA, - "TEST01", "PAT01", "PARAM02", 8.35, "", "LAST", 8.35, 0, + "TEST01", "PAT01", "PARAM02", NA, NA_character_, "LAST", 8.35, NA, + "TEST01", "PAT01", "PARAM02", 8.35, NA_character_, "LAST", 8.35, 0, "TEST01", "PAT02", "PARAM01", 29, "Y", "LAST", 29, 0, - "TEST01", "PAT02", "PARAM01", 19.7, "", "LAST", 29, -32.06897, - "TEST01", "PAT02", "PARAM01", 18.01, "", "LAST", 29, -37.89655, + "TEST01", "PAT02", "PARAM01", 19.7, NA_character_, "LAST", 29, -32.06897, + "TEST01", "PAT02", "PARAM01", 18.01, NA_character_, "LAST", 29, -37.89655, "TEST01", "PAT02", "PARAM02", 8.9, "Y", "LAST", 8.9, 0, - "TEST01", "PAT02", "PARAM02", 9, "", "LAST", 8.9, 1.123596, - "TEST01", "PAT02", "PARAM02", 5.35, "", "LAST", 8.9, -39.88764 + "TEST01", "PAT02", "PARAM02", 9, NA_character_, "LAST", 8.9, 1.123596, + "TEST01", "PAT02", "PARAM02", 5.35, NA_character_, "LAST", 8.9, -39.88764 ) expect_equal(derive_var_pchg(input)$PCHG, expected_output$PCHG, tolerance = 1e-5) @@ -73,15 +73,15 @@ test_that("`PCHG` is set to `NA` if `BASE == 0`", { input <- tibble::tribble( ~STUDYID, ~USUBJID, ~PARAMCD, ~AVAL, ~ABLFL, ~BASETYPE, ~BASE, ~CHG, "TEST01", "PAT01", "PARAM01", 0, "Y", "LAST", 0, 0, - "TEST01", "PAT01", "PARAM01", 1.7, "", "LAST", 0, 1.7, - "TEST01", "PAT01", "PARAM01", 3.01, "", "LAST", 0, 3.01, + "TEST01", "PAT01", "PARAM01", 1.7, NA_character_, "LAST", 0, 1.7, + "TEST01", "PAT01", "PARAM01", 3.01, NA_character_, "LAST", 0, 3.01, ) expected_output <- tibble::tribble( ~STUDYID, ~USUBJID, ~PARAMCD, ~AVAL, ~ABLFL, ~BASETYPE, ~BASE, ~CHG, ~PCHG, "TEST01", "PAT01", "PARAM01", 0, "Y", "LAST", 0, 0, NA_real_, - "TEST01", "PAT01", "PARAM01", 1.7, "", "LAST", 0, 1.7, NA_real_, - "TEST01", "PAT01", "PARAM01", 3.01, "", "LAST", 0, 3.01, NA_real_, + "TEST01", "PAT01", "PARAM01", 1.7, NA_character_, "LAST", 0, 1.7, NA_real_, + "TEST01", "PAT01", "PARAM01", 3.01, NA_character_, "LAST", 0, 3.01, NA_real_, ) expect_equal(derive_var_pchg(input)$PCHG, expected_output$PCHG, tolerance = 1e-7) diff --git a/tests/testthat/test-derive_var_shift.R b/tests/testthat/test-derive_var_shift.R index 9e690b8e63..5bca781a0d 100644 --- a/tests/testthat/test-derive_var_shift.R +++ b/tests/testthat/test-derive_var_shift.R @@ -5,17 +5,17 @@ test_that("derive_var_shift Test 1: Shift based on character variables", { input <- tibble::tribble( ~USUBJID, ~PARAMCD, ~AVAL, ~ABLFL, ~BNRIND, ~ANRIND, "P01", "ALB", 33, "Y", "LOW", "LOW", - "P01", "ALB", 38, NA, "LOW", "NORMAL", + "P01", "ALB", 38, NA_character_, "LOW", "NORMAL", "P02", "ALB", 37, "Y", "NORMAL", "NORMAL", - "P02", "ALB", 49, NA, "NORMAL", "HIGH", + "P02", "ALB", 49, NA_character_, "NORMAL", "HIGH", "P02", "SODIUM", 147, "Y", "HIGH", "HIGH" ) expected_output <- tibble::tribble( ~USUBJID, ~PARAMCD, ~AVAL, ~ABLFL, ~BNRIND, ~ANRIND, ~SHIFT1, "P01", "ALB", 33, "Y", "LOW", "LOW", "LOW to LOW", - "P01", "ALB", 38, NA, "LOW", "NORMAL", "LOW to NORMAL", + "P01", "ALB", 38, NA_character_, "LOW", "NORMAL", "LOW to NORMAL", "P02", "ALB", 37, "Y", "NORMAL", "NORMAL", "NORMAL to NORMAL", - "P02", "ALB", 49, NA, "NORMAL", "HIGH", "NORMAL to HIGH", + "P02", "ALB", 49, NA_character_, "NORMAL", "HIGH", "NORMAL to HIGH", "P02", "SODIUM", 147, "Y", "HIGH", "HIGH", "HIGH to HIGH" ) @@ -36,19 +36,19 @@ test_that("derive_var_shift Test 2: Shift based on character variables with miss input <- tibble::tribble( ~USUBJID, ~PARAMCD, ~AVAL, ~ABLFL, ~BNRIND, ~ANRIND, "P01", "ALB", 33, "Y", "LOW", "LOW", - "P01", "ALB", 38, NA, "LOW", "NORMAL", - "P01", "ALB", NA, NA, "LOW", NA, + "P01", "ALB", 38, NA_character_, "LOW", "NORMAL", + "P01", "ALB", NA, NA_character_, "LOW", NA, "P02", "ALB", NA, "Y", NA, NA, - "P02", "ALB", 49, NA, NA, "HIGH", + "P02", "ALB", 49, NA_character_, NA, "HIGH", "P02", "SODIUM", 147, "Y", "HIGH", "HIGH" ) expected_output <- tibble::tribble( ~USUBJID, ~PARAMCD, ~AVAL, ~ABLFL, ~BNRIND, ~ANRIND, ~SHIFT1, "P01", "ALB", 33, "Y", "LOW", "LOW", "LOW to LOW", - "P01", "ALB", 38, NA, "LOW", "NORMAL", "LOW to NORMAL", - "P01", "ALB", NA, NA, "LOW", NA, "LOW to NULL", + "P01", "ALB", 38, NA_character_, "LOW", "NORMAL", "LOW to NORMAL", + "P01", "ALB", NA, NA_character_, "LOW", NA, "LOW to NULL", "P02", "ALB", NA, "Y", NA, NA, "NULL to NULL", - "P02", "ALB", 49, NA, NA, "HIGH", "NULL to HIGH", + "P02", "ALB", 49, NA_character_, NA, "HIGH", "NULL to HIGH", "P02", "SODIUM", 147, "Y", "HIGH", "HIGH", "HIGH to HIGH" ) @@ -69,19 +69,19 @@ test_that("derive_var_shift Test 3: Shift based on numeric variables with missin input <- tibble::tribble( ~USUBJID, ~PARAMCD, ~AVAL, ~ABLFL, ~BASE, "P01", "ALB", 33.1, "Y", 33.1, - "P01", "ALB", 38.5, NA, 33.1, - "P01", "ALB", NA, NA, 33.1, + "P01", "ALB", 38.5, NA_character_, 33.1, + "P01", "ALB", NA, NA_character_, 33.1, "P02", "ALB", NA, "Y", NA, - "P02", "ALB", 49.0, NA, NA, + "P02", "ALB", 49.0, NA_character_, NA, "P02", "SODIUM", 147.5, "Y", 147.5 ) %>% convert_blanks_to_na() expected_output <- tibble::tribble( ~USUBJID, ~PARAMCD, ~AVAL, ~ABLFL, ~BASE, ~SHIFT2, "P01", "ALB", 33.1, "Y", 33.1, "33.1 to 33.1", - "P01", "ALB", 38.5, NA, 33.1, "33.1 to 38.5", - "P01", "ALB", NA, NA, 33.1, "33.1 to NULL", + "P01", "ALB", 38.5, NA_character_, 33.1, "33.1 to 38.5", + "P01", "ALB", NA, NA_character_, 33.1, "33.1 to NULL", "P02", "ALB", NA, "Y", NA, "NULL to NULL", - "P02", "ALB", 49, NA, NA, "NULL to 49", + "P02", "ALB", 49, NA_character_, NA, "NULL to 49", "P02", "SODIUM", 147.5, "Y", 147.5, "147.5 to 147.5" ) @@ -101,19 +101,19 @@ test_that("derive_var_shift Test 4: Shift with user-specified missing_value and input <- tibble::tribble( ~USUBJID, ~PARAMCD, ~AVAL, ~ABLFL, ~BNRIND, ~ANRIND, "P01", "ALB", 33, "Y", "LOW", "LOW", - "P01", "ALB", 38, NA, "LOW", "NORMAL", - "P01", "ALB", NA, NA, "LOW", NA, + "P01", "ALB", 38, NA_character_, "LOW", "NORMAL", + "P01", "ALB", NA, NA_character_, "LOW", NA, "P02", "ALB", NA, "Y", NA, NA, - "P02", "ALB", 49, NA, NA, "HIGH", + "P02", "ALB", 49, NA_character_, NA, "HIGH", "P02", "SODIUM", 147, "Y", "HIGH", "HIGH" ) expected_output <- tibble::tribble( ~USUBJID, ~PARAMCD, ~AVAL, ~ABLFL, ~BNRIND, ~ANRIND, ~SHIFT1, "P01", "ALB", 33, "Y", "LOW", "LOW", "LOW - LOW", - "P01", "ALB", 38, NA, "LOW", "NORMAL", "LOW - NORMAL", - "P01", "ALB", NA, NA, "LOW", NA, "LOW - MISSING", + "P01", "ALB", 38, NA_character_, "LOW", "NORMAL", "LOW - NORMAL", + "P01", "ALB", NA, NA_character_, "LOW", NA, "LOW - MISSING", "P02", "ALB", NA, "Y", NA, NA, "MISSING - MISSING", - "P02", "ALB", 49, NA, NA, "HIGH", "MISSING - HIGH", + "P02", "ALB", 49, NA_character_, NA, "HIGH", "MISSING - HIGH", "P02", "SODIUM", 147, "Y", "HIGH", "HIGH", "HIGH - HIGH" ) diff --git a/tests/testthat/test-derive_vars_computed.R b/tests/testthat/test-derive_vars_computed.R index 83b07bcbeb..71596780cf 100644 --- a/tests/testthat/test-derive_vars_computed.R +++ b/tests/testthat/test-derive_vars_computed.R @@ -10,17 +10,17 @@ test_that("derive_vars_computed Test 1: new variable is derived correctly", { advs <- tribble( ~STUDYID, ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~AVAL, ~AVALU, ~ABLFL, "PILOT01", "01-1302", "HEIGHT", "Height (cm)", "SCREENING", 177.8, "cm", "Y", - "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "SCREENING", 81.19, "kg", "N", + "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "SCREENING", 81.19, "kg", NA_character_, "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "BASELINE", 82.1, "kg", "Y", - "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "WEEK 2", 81.19, "kg", "N", - "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "WEEK 4", 82.56, "kg", "N", - "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "WEEK 6", 80.74, "kg", "N", + "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "WEEK 2", 81.19, "kg", NA_character_, + "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "WEEK 4", 82.56, "kg", NA_character_, + "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "WEEK 6", 80.74, "kg", NA_character_, "PILOT01", "17-1344", "HEIGHT", "Height (cm)", "SCREENING", 163.5, "cm", "Y", - "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "SCREENING", 58.06, "kg", "N", + "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "SCREENING", 58.06, "kg", NA_character_, "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "BASELINE", 58.06, "kg", "Y", - "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "WEEK 2", 58.97, "kg", "N", - "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "WEEK 4", 57.97, "kg", "N", - "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "WEEK 6", 58.97, "kg", "N" + "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "WEEK 2", 58.97, "kg", NA_character_, + "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "WEEK 4", 57.97, "kg", NA_character_, + "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "WEEK 6", 58.97, "kg", NA_character_ ) expected_output <- adsl %>% @@ -57,17 +57,17 @@ test_that("derive_vars_computed Test 2: no new variables added if filtered datas advs <- tribble( ~STUDYID, ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~AVAL, ~AVALU, ~ABLFL, "PILOT01", "01-1302", "HEIGHT", "Height (cm)", "SCREENING", 177.8, "cm", "Y", - "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "SCREENING", 81.19, "kg", "N", + "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "SCREENING", 81.19, "kg", NA_character_, "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "BASELINE", 82.1, "kg", "Y", - "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "WEEK 2", 81.19, "kg", "N", - "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "WEEK 4", 82.56, "kg", "N", - "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "WEEK 6", 80.74, "kg", "N", + "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "WEEK 2", 81.19, "kg", NA_character_, + "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "WEEK 4", 82.56, "kg", NA_character_, + "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "WEEK 6", 80.74, "kg", NA_character_, "PILOT01", "17-1344", "HEIGHT", "Height (cm)", "SCREENING", 163.5, "cm", "Y", - "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "SCREENING", 58.06, "kg", "N", + "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "SCREENING", 58.06, "kg", NA_character_, "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "BASELINE", 58.06, "kg", "Y", - "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "WEEK 2", 58.97, "kg", "N", - "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "WEEK 4", 57.97, "kg", "N", - "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "WEEK 6", 58.97, "kg", "N" + "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "WEEK 2", 58.97, "kg", NA_character_, + "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "WEEK 4", 57.97, "kg", NA_character_, + "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "WEEK 6", 58.97, "kg", NA_character_ ) expected <- adsl %>% @@ -101,16 +101,16 @@ test_that("derive_vars_computed Test 3: no new variables are added if a paramete advs <- tribble( ~STUDYID, ~USUBJID, ~PARAMCD, ~PARAM, ~VISIT, ~AVAL, ~AVALU, ~ABLFL, - "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "SCREENING", 81.19, "kg", "N", + "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "SCREENING", 81.19, "kg", NA_character_, "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "BASELINE", 82.1, "kg", "Y", - "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "WEEK 2", 81.19, "kg", "N", - "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "WEEK 4", 82.56, "kg", "N", - "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "WEEK 6", 80.74, "kg", "N", - "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "SCREENING", 58.06, "kg", "N", + "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "WEEK 2", 81.19, "kg", NA_character_, + "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "WEEK 4", 82.56, "kg", NA_character_, + "PILOT01", "01-1302", "WEIGHT", "Weight (kg)", "WEEK 6", 80.74, "kg", NA_character_, + "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "SCREENING", 58.06, "kg", NA_character_, "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "BASELINE", 58.06, "kg", "Y", - "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "WEEK 2", 58.97, "kg", "N", - "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "WEEK 4", 57.97, "kg", "N", - "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "WEEK 6", 58.97, "kg", "N" + "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "WEEK 2", 58.97, "kg", NA_character_, + "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "WEEK 4", 57.97, "kg", NA_character_, + "PILOT01", "17-1344", "WEIGHT", "Weight (kg)", "WEEK 6", 58.97, "kg", NA_character_ ) expected <- adsl %>% From 4a307141b9e4bc396d28292bb91c4f7b77bbc0d1 Mon Sep 17 00:00:00 2001 From: bms63 Date: Thu, 12 Dec 2024 18:01:10 +0000 Subject: [PATCH 2/2] [skip actions] Bump version to 1.1.1.9038 --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7f596e6d26..64a9cf2625 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: admiral Title: ADaM in R Asset Library -Version: 1.1.1.9037 +Version: 1.1.1.9038 Authors@R: c( person("Ben", "Straub", , "ben.x.straub@gsk.com", role = c("aut", "cre")), person("Stefan", "Bundfuss", role = "aut",