Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #2582 update derive_vars_period #2583

Merged
merged 5 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
clarkliming marked this conversation as resolved.
Show resolved Hide resolved

## Updates of Existing Functions

Expand Down
1 change: 1 addition & 0 deletions R/period_dataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)

Expand Down
41 changes: 41 additions & 0 deletions tests/testthat/test-period_dataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
clarkliming marked this conversation as resolved.
Show resolved Hide resolved
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")
)
})
Loading