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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,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)

- In `get_summary_records()`, previously deprecated formal arguments `analysis_var` and `summary_fun` now removed from function, documentation, tests etc. (#2521)

## Breaking Changes
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 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",
"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")
)
})