From 89e312df0c06a0a002d0e19dfd140237168465c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Liming=20Li=20=EF=BC=88=E6=9D=8E=E9=BB=8E=E6=98=8E?= =?UTF-8?q?=EF=BC=89?= Date: Thu, 28 Nov 2024 03:13:07 +0000 Subject: [PATCH 1/3] fix issue --- R/period_dataset.R | 1 + tests/testthat/test-period_dataset.R | 41 ++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/R/period_dataset.R b/R/period_dataset.R index 01fa37ce5d..5a37aa2a6c 100644 --- a/R/period_dataset.R +++ b/R/period_dataset.R @@ -419,6 +419,7 @@ derive_vars_period <- function(dataset, ref_wide <- pivot_wider( ref_stripped, names_from = vars2chr(id_vars), + names_glue = sprintf("{.value}_%s", paste0(sprintf("{%s}", vars2chr(id_vars)), collapse = "_")), values_from = unname(new_vars_chr) ) diff --git a/tests/testthat/test-period_dataset.R b/tests/testthat/test-period_dataset.R index 69a214c525..e26f9650a2 100644 --- a/tests/testthat/test-period_dataset.R +++ b/tests/testthat/test-period_dataset.R @@ -433,3 +433,44 @@ test_that("derive_vars_period Test 13: periods", { keys = c("USUBJID") ) }) + +## Test 14: Periods derived even when only when one period variable needed ---- +test_that("derive_vars_period Test 13: periods", { + expected <- tibble::tribble( + ~USUBJID, ~AP01SDT, + "1", "2021-01-04", + "2", "2021-02-02", + ) %>% + mutate( + across(matches("AP\\d\\d[ES]DT"), ymd) + ) %>% + mutate( + STUDYID = "xyz" + ) + + period_ref <- tibble::tribble( + ~USUBJID, ~APERIOD, ~APERSDT, ~APEREDT, ~APERSDTM, ~APEREDTM, + "1", 1, "2021-01-04", "2021-02-06", "2021-01-04 10:01:02", "2021-02-06 14:03:04", + "2", 1, "2021-02-02", "2021-03-02", "2021-02-02 04:11:34", "2021-03-02 16:55:59" + ) %>% + mutate( + STUDYID = "xyz", + APERIOD = as.integer(APERIOD), + APERSDT = ymd(APERSDT), + APEREDT = ymd(APEREDT), + APERSDTM = ymd_hms(APERSDTM), + APEREDTM = ymd_hms(APEREDTM) + ) + + adsl <- tibble::tibble(STUDYID = "xyz", USUBJID = c("1", "2")) + + expect_dfs_equal( + base = expected, + compare = derive_vars_period( + adsl, + dataset_ref = period_ref, + new_vars = exprs(APxxSDT = APERSDT) + ), + keys = c("USUBJID") + ) +}) From 9c46c8bbdb891df358e9409d998d95140738862a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Liming=20Li=20=EF=BC=88=E6=9D=8E=E9=BB=8E=E6=98=8E?= =?UTF-8?q?=EF=BC=89?= Date: Thu, 28 Nov 2024 03:18:30 +0000 Subject: [PATCH 2/3] update readme --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index 5bd3cd8f67..332403e502 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,6 +10,7 @@ - Remove `dthcaus_source()` calls in `ADSL` template because they are deprecated. (#2517) - Update `ADEG` template to flag `ABLFL` and `ANL01FL` based on `DTYPE == "AVERAGE"` records. (#2561) +- Update `derive_vars_period` to make it work when there is only one new variable. (#2582) ## Updates of Existing Functions From 5717607eddd64006c2e6e2deae120f142e1ba10a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Liming=20Li=20=EF=BC=88=E6=9D=8E=E9=BB=8E=E6=98=8E?= =?UTF-8?q?=EF=BC=89?= Date: Thu, 28 Nov 2024 14:10:00 +0000 Subject: [PATCH 3/3] update tests --- NEWS.md | 3 ++- tests/testthat/test-period_dataset.R | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index 332403e502..f5bc0f0ebd 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,7 +10,6 @@ - Remove `dthcaus_source()` calls in `ADSL` template because they are deprecated. (#2517) - Update `ADEG` template to flag `ABLFL` and `ANL01FL` based on `DTYPE == "AVERAGE"` records. (#2561) -- Update `derive_vars_period` to make it work when there is only one new variable. (#2582) ## Updates of Existing Functions @@ -40,6 +39,8 @@ or that the queries dataset contains duplicates. (#2543) - test scripts, R, and markdown files for `create_single_dose_dataset` and `occds.Rmd` updated to include a `STUDYID` column because of `get_admiral_option("subject_keys")` update above. (#2501) +- Update `derive_vars_period()` to make it work when there is only one new variable. (#2582) + ## Breaking Changes - The following function arguments are entering the next phase of the deprecation process: (#2487) diff --git a/tests/testthat/test-period_dataset.R b/tests/testthat/test-period_dataset.R index e26f9650a2..8ccfac5c1d 100644 --- a/tests/testthat/test-period_dataset.R +++ b/tests/testthat/test-period_dataset.R @@ -434,8 +434,8 @@ test_that("derive_vars_period Test 13: periods", { ) }) -## Test 14: Periods derived even when only when one period variable needed ---- -test_that("derive_vars_period Test 13: periods", { +## Test 14: periods variable derived when only one variable needed ---- +test_that("derive_vars_period Test 14: periods variable derived when only one variable needed", { expected <- tibble::tribble( ~USUBJID, ~AP01SDT, "1", "2021-01-04",