From 3ba3590d5277707bdf28050dabc4f97c8bab519a Mon Sep 17 00:00:00 2001 From: ProfessorP Date: Sat, 28 Sep 2024 19:34:00 -0400 Subject: [PATCH 01/13] Updated the derive_vars and create_single_dose_dataset function by_vars argument to use get_admiral_option("subject_keys"). Came across an issue during pkgdown checklist with bds_exposure.R lines 365-366 with !!!adsl_vars --- NEWS.md | 1 + R/create_single_dose_dataset.R | 8 ++++---- R/derive_vars_transposed.R | 2 +- admiral | 1 + man/create_single_dose_dataset.Rd | 10 +++++----- man/derive_vars_atc.Rd | 2 +- vignettes/bds_exposure.Rmd | 2 +- 7 files changed, 14 insertions(+), 12 deletions(-) create mode 160000 admiral diff --git a/NEWS.md b/NEWS.md index 062fe72995..1b3197e91a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,6 +10,7 @@ ## Updates of Existing Functions +- `derive_vars_atc()` and `create_single_dose_dataset()` had their `by_vars` argument updated to `get_admiral_option("subject_keys")` (#2501) - Templates for ADPC, ADPPK and ADPP are updated to handle urine records. (#2392) - `basket_select()` function updated to add `...` argument to allow other qualifiers to be passed to user-defined function specified in `get_terms_fun()` argument for function `create_query_data()`. (#2265) - Update PK Programming vignette and templates for ADPC and ADPPK for the nominal time formula `NFRLT` to reduce duplicate records in dose expansion with `create_single_dose_dataset()`. (#2426) diff --git a/R/create_single_dose_dataset.R b/R/create_single_dose_dataset.R index 7d255ad9d1..e0c7cfbdab 100644 --- a/R/create_single_dose_dataset.R +++ b/R/create_single_dose_dataset.R @@ -342,7 +342,7 @@ dose_freq_lookup <- tribble( #' lookup_column = CDISC_VALUE, #' nominal_time = NFRLT, #' keep_source_vars = exprs( -#' USUBJID, EXDOSFRQ, ASTDT, ASTDTM, AENDT, AENDTM, NFRLT +#' get_admiral_option("subject_keys"), EXDOSFRQ, ASTDT, ASTDTM, AENDT, AENDTM, NFRLT #' ) #' ) #' @@ -397,7 +397,7 @@ dose_freq_lookup <- tribble( #' # Select valid dose records, non-missing `EXSTDTC` and `EXDOSE`. #' ex_mod <- ex %>% #' filter(!is.na(EXSTDTC) & !is.na(EXDOSE)) %>% -#' derive_vars_merged(adsl_death, by_vars = exprs(STUDYID, USUBJID)) %>% +#' derive_vars_merged(adsl_death, by_vars = get_admiral_option("subject_keys")) %>% #' # Example, set up missing `EXDOSFRQ` as QD daily dosing regime. #' # Replace with study dosing regime per trial treatment. #' mutate(EXDOSFRQ = if_else(is.na(EXDOSFRQ), "QD", EXDOSFRQ)) %>% @@ -436,7 +436,7 @@ dose_freq_lookup <- tribble( #' end_date = EXENDT, #' end_datetime = EXENDTM, #' keep_source_vars = exprs( -#' STUDYID, USUBJID, EXTRT, EXDOSE, EXDOSFRQ, +#' get_admiral_option("subject_keys"), EXTRT, EXDOSE, EXDOSFRQ, #' DCUTDT, EXSTDT, EXSTDTM, EXENDT, EXENDTM, EXSTDTC, EXENDTC #' ) #' ) @@ -450,7 +450,7 @@ create_single_dose_dataset <- function(dataset, lookup_column = CDISC_VALUE, nominal_time = NULL, keep_source_vars = expr_c( - exprs(USUBJID), dose_freq, start_date, start_datetime, + get_admiral_option("subject_keys"), dose_freq, start_date, start_datetime, end_date, end_datetime )) { dose_freq <- assert_symbol(enexpr(dose_freq)) diff --git a/R/derive_vars_transposed.R b/R/derive_vars_transposed.R index 799bb27145..556274a2fc 100644 --- a/R/derive_vars_transposed.R +++ b/R/derive_vars_transposed.R @@ -168,7 +168,7 @@ derive_vars_transposed <- function(dataset, #' derive_vars_atc(cm, facm) derive_vars_atc <- function(dataset, dataset_facm, - by_vars = exprs(USUBJID, CMREFID = FAREFID), + by_vars = exprs(get_admiral_option("subject_keys"), CMREFID = FAREFID), value_var = FASTRESC) { value_var <- assert_symbol(enexpr(value_var)) assert_vars(by_vars) diff --git a/admiral b/admiral new file mode 160000 index 0000000000..680074a110 --- /dev/null +++ b/admiral @@ -0,0 +1 @@ +Subproject commit 680074a1108342da74e8e08487124b26a68e992f diff --git a/man/create_single_dose_dataset.Rd b/man/create_single_dose_dataset.Rd index a89b34fd83..10460760ec 100644 --- a/man/create_single_dose_dataset.Rd +++ b/man/create_single_dose_dataset.Rd @@ -14,8 +14,8 @@ create_single_dose_dataset( lookup_table = dose_freq_lookup, lookup_column = CDISC_VALUE, nominal_time = NULL, - keep_source_vars = expr_c(exprs(USUBJID), dose_freq, start_date, start_datetime, - end_date, end_datetime) + keep_source_vars = expr_c(get_admiral_option("subject_keys"), dose_freq, start_date, + start_datetime, end_date, end_datetime) ) } \arguments{ @@ -178,7 +178,7 @@ create_single_dose_dataset(data, lookup_column = CDISC_VALUE, nominal_time = NFRLT, keep_source_vars = exprs( - USUBJID, EXDOSFRQ, ASTDT, ASTDTM, AENDT, AENDTM, NFRLT + get_admiral_option("subject_keys"), EXDOSFRQ, ASTDT, ASTDTM, AENDT, AENDTM, NFRLT ) ) @@ -233,7 +233,7 @@ adsl_death <- adsl \%>\% # Select valid dose records, non-missing `EXSTDTC` and `EXDOSE`. ex_mod <- ex \%>\% filter(!is.na(EXSTDTC) & !is.na(EXDOSE)) \%>\% - derive_vars_merged(adsl_death, by_vars = exprs(STUDYID, USUBJID)) \%>\% + derive_vars_merged(adsl_death, by_vars = get_admiral_option("subject_keys")) \%>\% # Example, set up missing `EXDOSFRQ` as QD daily dosing regime. # Replace with study dosing regime per trial treatment. mutate(EXDOSFRQ = if_else(is.na(EXDOSFRQ), "QD", EXDOSFRQ)) \%>\% @@ -272,7 +272,7 @@ create_single_dose_dataset( end_date = EXENDT, end_datetime = EXENDTM, keep_source_vars = exprs( - STUDYID, USUBJID, EXTRT, EXDOSE, EXDOSFRQ, + get_admiral_option("subject_keys"), EXTRT, EXDOSE, EXDOSFRQ, DCUTDT, EXSTDT, EXSTDTM, EXENDT, EXENDTM, EXSTDTC, EXENDTC ) ) diff --git a/man/derive_vars_atc.Rd b/man/derive_vars_atc.Rd index c3b0a473f1..a41a260db9 100644 --- a/man/derive_vars_atc.Rd +++ b/man/derive_vars_atc.Rd @@ -7,7 +7,7 @@ derive_vars_atc( dataset, dataset_facm, - by_vars = exprs(USUBJID, CMREFID = FAREFID), + by_vars = exprs(get_admiral_option("subject_keys"), CMREFID = FAREFID), value_var = FASTRESC ) } diff --git a/vignettes/bds_exposure.Rmd b/vignettes/bds_exposure.Rmd index 4debbc39d2..4b331bea1e 100644 --- a/vignettes/bds_exposure.Rmd +++ b/vignettes/bds_exposure.Rmd @@ -362,7 +362,7 @@ For example, to calculate the total dose by subject and treatment, adex <- derive_param_exposure( adex, dataset_add = adex, - by_vars = exprs(STUDYID, USUBJID, !!!adsl_vars), + by_vars = c(exprs(STUDYID, USUBJID), !!!adsl_vars)), input_code = "DOSE", set_values_to = exprs( PARAMCD = "TDOSE", From d358fa0ca9a0eb49ac75ccf4a8633162e59eaf6f Mon Sep 17 00:00:00 2001 From: ProfessorP Date: Sat, 28 Sep 2024 20:01:05 -0400 Subject: [PATCH 02/13] Removed a duplicate of the admiral code within the admiral package I must've pulled by mistake. Updated Functions and fixed an error when replacing UBSUBJID, STUDYID with get_admiral_options("Subject_keys) --- R/create_single_dose_dataset.R | 7 ++++--- R/derive_vars_transposed.R | 2 +- admiral | 1 - 3 files changed, 5 insertions(+), 5 deletions(-) delete mode 160000 admiral diff --git a/R/create_single_dose_dataset.R b/R/create_single_dose_dataset.R index e0c7cfbdab..e99b7280eb 100644 --- a/R/create_single_dose_dataset.R +++ b/R/create_single_dose_dataset.R @@ -342,7 +342,7 @@ dose_freq_lookup <- tribble( #' lookup_column = CDISC_VALUE, #' nominal_time = NFRLT, #' keep_source_vars = exprs( -#' get_admiral_option("subject_keys"), EXDOSFRQ, ASTDT, ASTDTM, AENDT, AENDTM, NFRLT +#' USUBJID, EXDOSFRQ, ASTDT, ASTDTM, AENDT, AENDTM, NFRLT #' ) #' ) #' @@ -436,7 +436,7 @@ dose_freq_lookup <- tribble( #' end_date = EXENDT, #' end_datetime = EXENDTM, #' keep_source_vars = exprs( -#' get_admiral_option("subject_keys"), EXTRT, EXDOSE, EXDOSFRQ, +#' STUDYID, USUBJID, EXTRT, EXDOSE, EXDOSFRQ, #' DCUTDT, EXSTDT, EXSTDTM, EXENDT, EXENDTM, EXSTDTC, EXENDTC #' ) #' ) @@ -450,7 +450,8 @@ create_single_dose_dataset <- function(dataset, lookup_column = CDISC_VALUE, nominal_time = NULL, keep_source_vars = expr_c( - get_admiral_option("subject_keys"), dose_freq, start_date, start_datetime, + get_admiral_option("subject_keys"), dose_freq, + start_date, start_datetime, end_date, end_datetime )) { dose_freq <- assert_symbol(enexpr(dose_freq)) diff --git a/R/derive_vars_transposed.R b/R/derive_vars_transposed.R index 556274a2fc..008d80d345 100644 --- a/R/derive_vars_transposed.R +++ b/R/derive_vars_transposed.R @@ -168,7 +168,7 @@ derive_vars_transposed <- function(dataset, #' derive_vars_atc(cm, facm) derive_vars_atc <- function(dataset, dataset_facm, - by_vars = exprs(get_admiral_option("subject_keys"), CMREFID = FAREFID), + by_vars = c(get_admiral_option("subject_keys"), exprs(CMREFID = FAREFID)), value_var = FASTRESC) { value_var <- assert_symbol(enexpr(value_var)) assert_vars(by_vars) diff --git a/admiral b/admiral deleted file mode 160000 index 680074a110..0000000000 --- a/admiral +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 680074a1108342da74e8e08487124b26a68e992f From ecd250010277328dc48012dcd2e04238e76073cf Mon Sep 17 00:00:00 2001 From: ProfessorP Date: Tue, 1 Oct 2024 11:06:54 -0400 Subject: [PATCH 03/13] I tried to address the failure in package building by changing bds_exposure.Rmd line 365 but still get Argument `enexpr(analysis_var)` must be a , but is missing. --- R/derive_vars_transposed.R | 3 ++- man/create_single_dose_dataset.Rd | 4 ++-- man/derive_vars_atc.Rd | 2 +- vignettes/bds_exposure.Rmd | 6 +++--- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/R/derive_vars_transposed.R b/R/derive_vars_transposed.R index 008d80d345..9b54c2829f 100644 --- a/R/derive_vars_transposed.R +++ b/R/derive_vars_transposed.R @@ -168,7 +168,8 @@ derive_vars_transposed <- function(dataset, #' derive_vars_atc(cm, facm) derive_vars_atc <- function(dataset, dataset_facm, - by_vars = c(get_admiral_option("subject_keys"), exprs(CMREFID = FAREFID)), + by_vars = c(get_admiral_option("subject_keys"), + exprs(CMREFID = FAREFID)), value_var = FASTRESC) { value_var <- assert_symbol(enexpr(value_var)) assert_vars(by_vars) diff --git a/man/create_single_dose_dataset.Rd b/man/create_single_dose_dataset.Rd index 10460760ec..5cf64b359e 100644 --- a/man/create_single_dose_dataset.Rd +++ b/man/create_single_dose_dataset.Rd @@ -178,7 +178,7 @@ create_single_dose_dataset(data, lookup_column = CDISC_VALUE, nominal_time = NFRLT, keep_source_vars = exprs( - get_admiral_option("subject_keys"), EXDOSFRQ, ASTDT, ASTDTM, AENDT, AENDTM, NFRLT + USUBJID, EXDOSFRQ, ASTDT, ASTDTM, AENDT, AENDTM, NFRLT ) ) @@ -272,7 +272,7 @@ create_single_dose_dataset( end_date = EXENDT, end_datetime = EXENDTM, keep_source_vars = exprs( - get_admiral_option("subject_keys"), EXTRT, EXDOSE, EXDOSFRQ, + STUDYID, USUBJID, EXTRT, EXDOSE, EXDOSFRQ, DCUTDT, EXSTDT, EXSTDTM, EXENDT, EXENDTM, EXSTDTC, EXENDTC ) ) diff --git a/man/derive_vars_atc.Rd b/man/derive_vars_atc.Rd index a41a260db9..167cdd6acf 100644 --- a/man/derive_vars_atc.Rd +++ b/man/derive_vars_atc.Rd @@ -7,7 +7,7 @@ derive_vars_atc( dataset, dataset_facm, - by_vars = exprs(get_admiral_option("subject_keys"), CMREFID = FAREFID), + by_vars = c(get_admiral_option("subject_keys"), exprs(CMREFID = FAREFID)), value_var = FASTRESC ) } diff --git a/vignettes/bds_exposure.Rmd b/vignettes/bds_exposure.Rmd index 4b331bea1e..76cb3a0705 100644 --- a/vignettes/bds_exposure.Rmd +++ b/vignettes/bds_exposure.Rmd @@ -362,7 +362,7 @@ For example, to calculate the total dose by subject and treatment, adex <- derive_param_exposure( adex, dataset_add = adex, - by_vars = c(exprs(STUDYID, USUBJID), !!!adsl_vars)), + by_vars = c(get_admiral_option("subject_keys"), adsl_vars), input_code = "DOSE", set_values_to = exprs( PARAMCD = "TDOSE", @@ -442,7 +442,7 @@ adex <- adex %>% ) ), dataset_add = adex, - by_vars = exprs(STUDYID, USUBJID, !!!adsl_vars) + by_vars = c(get_admiral_option("subject_keys"), adsl_vars) ) count(adex, PARAMCD, PARCAT1) @@ -466,7 +466,7 @@ specified in the `by_vars` argument will be populated in this new record. ```{r eval=TRUE, echo=TRUE} adex <- adex %>% derive_param_doseint( - by_vars = exprs(STUDYID, USUBJID, !!!adsl_vars), + by_vars = c(get_admiral_option("subject_keys"), adsl_vars), set_values_to = exprs(PARAMCD = "TNDOSINT"), tadm_code = "TDOSE", tpadm_code = "TPDOSE" From 808f9de7f79bad3882d10065035ef91437bc293b Mon Sep 17 00:00:00 2001 From: ProfessorP Date: Tue, 1 Oct 2024 14:59:46 -0400 Subject: [PATCH 04/13] ran lintr again, styler, and roxygen. --- R/derive_vars_transposed.R | 6 ++++-- man/derive_vars_atc.Rd | 12 ++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/R/derive_vars_transposed.R b/R/derive_vars_transposed.R index 6366ab1b13..8045418385 100644 --- a/R/derive_vars_transposed.R +++ b/R/derive_vars_transposed.R @@ -258,8 +258,10 @@ derive_vars_transposed <- function(dataset, #' derive_vars_atc(cm, facm) derive_vars_atc <- function(dataset, dataset_facm, - by_vars = c(get_admiral_option("subject_keys"), - exprs(CMREFID = FAREFID)), + by_vars = c( + get_admiral_option("subject_keys"), + expr(CMREFID = FAREFID) + ), value_var = FASTRESC) { value_var <- assert_symbol(enexpr(value_var)) assert_vars(by_vars) diff --git a/man/derive_vars_atc.Rd b/man/derive_vars_atc.Rd index e3f8de9716..111e0b16ba 100644 --- a/man/derive_vars_atc.Rd +++ b/man/derive_vars_atc.Rd @@ -7,7 +7,7 @@ derive_vars_atc( dataset, dataset_facm, - by_vars = c(get_admiral_option("subject_keys"), exprs(CMREFID = FAREFID)), + by_vars = c(get_admiral_option("subject_keys"), expr(CMREFID = FAREFID)), value_var = FASTRESC ) } @@ -25,17 +25,17 @@ The variables specified by the \code{by_vars} and \code{value_var} parameters, Keys used to merge \code{dataset_facm} with \code{dataset}.} +\item{value_var}{The variable of \code{dataset_facm} containing the values of the +transposed variables + +Default: \code{FASTRESC}} + \item{id_vars}{ID variables Variables (excluding by_vars) that uniquely identify each observation in \code{dataset_merge}. \emph{Permitted Values}: list of variables created by \code{exprs()} e.g. \code{exprs(USUBJID, VISIT)}} - -\item{value_var}{The variable of \code{dataset_facm} containing the values of the -transposed variables - -Default: \code{FASTRESC}} } \value{ The input dataset with ATC variables added From e1ce1b6537e0e758c456438fa5d0e154af1ced99 Mon Sep 17 00:00:00 2001 From: ProfessorP Date: Tue, 1 Oct 2024 15:11:53 -0400 Subject: [PATCH 05/13] test changes to derive_vars_atc --- R/derive_vars_transposed.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/derive_vars_transposed.R b/R/derive_vars_transposed.R index 8045418385..2c06802dcf 100644 --- a/R/derive_vars_transposed.R +++ b/R/derive_vars_transposed.R @@ -260,7 +260,7 @@ derive_vars_atc <- function(dataset, dataset_facm, by_vars = c( get_admiral_option("subject_keys"), - expr(CMREFID = FAREFID) + CMREFID = FAREFID ), value_var = FASTRESC) { value_var <- assert_symbol(enexpr(value_var)) From c8922f3bb1768a24ca3fc75e76f21ecf3d8d1604 Mon Sep 17 00:00:00 2001 From: ProfessorP Date: Wed, 2 Oct 2024 09:53:24 -0400 Subject: [PATCH 06/13] changed derive_vars_atc by_vars to exprs(!!!get_admiral_option("subject_keys"), CMREFID = FAREFID) to address symbol expression error. --- R/derive_vars_transposed.R | 5 +++-- man/derive_vars_atc.Rd | 13 +++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/R/derive_vars_transposed.R b/R/derive_vars_transposed.R index 2c06802dcf..1c04d9c7c3 100644 --- a/R/derive_vars_transposed.R +++ b/R/derive_vars_transposed.R @@ -258,10 +258,11 @@ derive_vars_transposed <- function(dataset, #' derive_vars_atc(cm, facm) derive_vars_atc <- function(dataset, dataset_facm, - by_vars = c( - get_admiral_option("subject_keys"), + by_vars = exprs( + !!!get_admiral_option("subject_keys"), CMREFID = FAREFID ), + id_vars = NULL, value_var = FASTRESC) { value_var <- assert_symbol(enexpr(value_var)) assert_vars(by_vars) diff --git a/man/derive_vars_atc.Rd b/man/derive_vars_atc.Rd index 111e0b16ba..c442d4988c 100644 --- a/man/derive_vars_atc.Rd +++ b/man/derive_vars_atc.Rd @@ -7,7 +7,8 @@ derive_vars_atc( dataset, dataset_facm, - by_vars = c(get_admiral_option("subject_keys"), expr(CMREFID = FAREFID)), + by_vars = exprs(!!!get_admiral_option("subject_keys"), CMREFID = FAREFID), + id_vars = NULL, value_var = FASTRESC ) } @@ -25,17 +26,17 @@ The variables specified by the \code{by_vars} and \code{value_var} parameters, Keys used to merge \code{dataset_facm} with \code{dataset}.} -\item{value_var}{The variable of \code{dataset_facm} containing the values of the -transposed variables - -Default: \code{FASTRESC}} - \item{id_vars}{ID variables Variables (excluding by_vars) that uniquely identify each observation in \code{dataset_merge}. \emph{Permitted Values}: list of variables created by \code{exprs()} e.g. \code{exprs(USUBJID, VISIT)}} + +\item{value_var}{The variable of \code{dataset_facm} containing the values of the +transposed variables + +Default: \code{FASTRESC}} } \value{ The input dataset with ATC variables added From e908b48e8f25809cbc474d16f950ae1c42bf7770 Mon Sep 17 00:00:00 2001 From: ProfessorP Date: Wed, 2 Oct 2024 15:50:34 -0400 Subject: [PATCH 07/13] Added STUDYID column to fix error with derive_vars_atc after correcting by_vars. --- vignettes/occds.Rmd | 50 ++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/vignettes/occds.Rmd b/vignettes/occds.Rmd index f481bae96b..d08660d169 100644 --- a/vignettes/occds.Rmd +++ b/vignettes/occds.Rmd @@ -173,33 +173,33 @@ The expected result is the input dataset with ATC variables added. ```{r eval=TRUE} cm <- tibble::tribble( - ~USUBJID, ~CMGRPID, ~CMREFID, ~CMDECOD, - "BP40257-1001", "14", "1192056", "PARACETAMOL", - "BP40257-1001", "18", "2007001", "SOLUMEDROL", - "BP40257-1002", "19", "2791596", "SPIRONOLACTONE" + ~STUDYID, ~USUBJID, ~CMGRPID, ~CMREFID, ~CMDECOD, + "STUDY01", "BP40257-1001", "14", "1192056", "PARACETAMOL", + "STUDY01", "BP40257-1001", "18", "2007001", "SOLUMEDROL", + "STUDY01", "BP40257-1002", "19", "2791596", "SPIRONOLACTONE" ) facm <- tibble::tribble( - ~USUBJID, ~FAGRPID, ~FAREFID, ~FATESTCD, ~FASTRESC, - "BP40257-1001", "1", "1192056", "CMATC1CD", "N", - "BP40257-1001", "1", "1192056", "CMATC2CD", "N02", - "BP40257-1001", "1", "1192056", "CMATC3CD", "N02B", - "BP40257-1001", "1", "1192056", "CMATC4CD", "N02BE", - "BP40257-1001", "1", "2007001", "CMATC1CD", "D", - "BP40257-1001", "1", "2007001", "CMATC2CD", "D10", - "BP40257-1001", "1", "2007001", "CMATC3CD", "D10A", - "BP40257-1001", "1", "2007001", "CMATC4CD", "D10AA", - "BP40257-1001", "2", "2007001", "CMATC1CD", "D", - "BP40257-1001", "2", "2007001", "CMATC2CD", "D07", - "BP40257-1001", "2", "2007001", "CMATC3CD", "D07A", - "BP40257-1001", "2", "2007001", "CMATC4CD", "D07AA", - "BP40257-1001", "3", "2007001", "CMATC1CD", "H", - "BP40257-1001", "3", "2007001", "CMATC2CD", "H02", - "BP40257-1001", "3", "2007001", "CMATC3CD", "H02A", - "BP40257-1001", "3", "2007001", "CMATC4CD", "H02AB", - "BP40257-1002", "1", "2791596", "CMATC1CD", "C", - "BP40257-1002", "1", "2791596", "CMATC2CD", "C03", - "BP40257-1002", "1", "2791596", "CMATC3CD", "C03D", - "BP40257-1002", "1", "2791596", "CMATC4CD", "C03DA" + ~STUDYID, ~USUBJID, ~FAGRPID, ~FAREFID, ~FATESTCD, ~FASTRESC, + "STUDY01", "BP40257-1001", "1", "1192056", "CMATC1CD", "N", + "STUDY01", "BP40257-1001", "1", "1192056", "CMATC2CD", "N02", + "STUDY01", "BP40257-1001", "1", "1192056", "CMATC3CD", "N02B", + "STUDY01", "BP40257-1001", "1", "1192056", "CMATC4CD", "N02BE", + "STUDY01", "BP40257-1001", "1", "2007001", "CMATC1CD", "D", + "STUDY01", "BP40257-1001", "1", "2007001", "CMATC2CD", "D10", + "STUDY01", "BP40257-1001", "1", "2007001", "CMATC3CD", "D10A", + "STUDY01", "BP40257-1001", "1", "2007001", "CMATC4CD", "D10AA", + "STUDY01", "BP40257-1001", "2", "2007001", "CMATC1CD", "D", + "STUDY01", "BP40257-1001", "2", "2007001", "CMATC2CD", "D07", + "STUDY01", "BP40257-1001", "2", "2007001", "CMATC3CD", "D07A", + "STUDY01", "BP40257-1001", "2", "2007001", "CMATC4CD", "D07AA", + "STUDY01", "BP40257-1001", "3", "2007001", "CMATC1CD", "H", + "STUDY01", "BP40257-1001", "3", "2007001", "CMATC2CD", "H02", + "STUDY01", "BP40257-1001", "3", "2007001", "CMATC3CD", "H02A", + "STUDY01", "BP40257-1001", "3", "2007001", "CMATC4CD", "H02AB", + "STUDY01", "BP40257-1002", "1", "2791596", "CMATC1CD", "C", + "STUDY01", "BP40257-1002", "1", "2791596", "CMATC2CD", "C03", + "STUDY01", "BP40257-1002", "1", "2791596", "CMATC3CD", "C03D", + "STUDY01", "BP40257-1002", "1", "2791596", "CMATC4CD", "C03DA" ) derive_vars_atc(cm, facm) From 6ff41a3d0b29bb9320074b45da875b82bb941547 Mon Sep 17 00:00:00 2001 From: ProfessorP Date: Wed, 2 Oct 2024 19:15:48 -0400 Subject: [PATCH 08/13] Ran devtools::test() and corrected errors that required a STUDYID column and formatting --- NEWS.md | 3 +- R/create_single_dose_dataset.R | 22 +- R/derive_vars_transposed.R | 50 ++-- man/create_single_dose_dataset.Rd | 22 +- man/derive_vars_atc.Rd | 50 ++-- .../_snaps/create_single_dose_dataset.md | 3 +- .../testthat/_snaps/derive_vars_transposed.md | 17 +- .../test-create_single_dose_dataset.R | 243 +++++++++--------- tests/testthat/test-derive_vars_transposed.R | 167 ++++++------ vignettes/occds.Rmd | 50 ++-- 10 files changed, 316 insertions(+), 311 deletions(-) diff --git a/NEWS.md b/NEWS.md index 7bb95dc688..8d921d3ab2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -45,7 +45,8 @@ # admiral 1.1.1 - +- `derive_vars_atc()` and `create_single_dose_dataset()` `by_vars` argument updated to use `get_admiral_option("subject_keys")` instead of hardcoded USUBJID or STUDYID. +- test scripts, R, and Rmd files for `create_single_dose_dataset` and `occds.Rmd` updated to include a STUDYID column because of `get_admiral_option("subject_keys")` update above. - `derive_extreme_event()` was fixed such that `check_type = "none"` is accepted again. (#2462) diff --git a/R/create_single_dose_dataset.R b/R/create_single_dose_dataset.R index 821e672067..1570a3e01c 100644 --- a/R/create_single_dose_dataset.R +++ b/R/create_single_dose_dataset.R @@ -287,12 +287,12 @@ dose_freq_lookup <- tribble( #' library(dplyr) #' #' data <- tribble( -#' ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, -#' "P01", "Q2D", ymd("2021-01-01"), ymd_hms("2021-01-01 10:30:00"), +#' ~STUDYID, ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, +#' "STUDY01", "P01", "Q2D", ymd("2021-01-01"), ymd_hms("2021-01-01 10:30:00"), #' ymd("2021-01-07"), ymd_hms("2021-01-07 11:30:00"), -#' "P01", "Q3D", ymd("2021-01-08"), ymd_hms("2021-01-08 12:00:00"), +#' "STUDY01", "P01", "Q3D", ymd("2021-01-08"), ymd_hms("2021-01-08 12:00:00"), #' ymd("2021-01-14"), ymd_hms("2021-01-14 14:00:00"), -#' "P01", "EVERY 2 WEEKS", ymd("2021-01-15"), ymd_hms("2021-01-15 09:57:00"), +#' "STUDY01", "P01", "EVERY 2 WEEKS", ymd("2021-01-15"), ymd_hms("2021-01-15 09:57:00"), #' ymd("2021-01-29"), ymd_hms("2021-01-29 10:57:00") #' ) #' @@ -307,10 +307,10 @@ dose_freq_lookup <- tribble( #' ) #' #' data <- tribble( -#' ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, -#' "P01", "Q30MIN", ymd("2021-01-01"), ymd_hms("2021-01-01T06:00:00"), +#' ~STUDYID, ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, +#' "STUDY01", "P01", "Q30MIN", ymd("2021-01-01"), ymd_hms("2021-01-01T06:00:00"), #' ymd("2021-01-01"), ymd_hms("2021-01-01T07:00:00"), -#' "P02", "Q90MIN", ymd("2021-01-01"), ymd_hms("2021-01-01T06:00:00"), +#' "STUDY02", "P02", "Q90MIN", ymd("2021-01-01"), ymd_hms("2021-01-01T06:00:00"), #' ymd("2021-01-01"), ymd_hms("2021-01-01T09:00:00") #' ) #' @@ -323,12 +323,12 @@ dose_freq_lookup <- tribble( #' # Example with nominal time #' #' data <- tribble( -#' ~USUBJID, ~EXDOSFRQ, ~NFRLT, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, -#' "P01", "BID", 0, ymd("2021-01-01"), ymd_hms("2021-01-01 08:00:00"), +#' ~STUDYID, ~USUBJID, ~EXDOSFRQ, ~NFRLT, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, +#' "STUDY01", "P01", "BID", 0, ymd("2021-01-01"), ymd_hms("2021-01-01 08:00:00"), #' ymd("2021-01-07"), ymd_hms("2021-01-07 20:00:00"), -#' "P01", "BID", 168, ymd("2021-01-08"), ymd_hms("2021-01-08 08:00:00"), +#' "STUDY01", "P01", "BID", 168, ymd("2021-01-08"), ymd_hms("2021-01-08 08:00:00"), #' ymd("2021-01-14"), ymd_hms("2021-01-14 20:00:00"), -#' "P01", "BID", 336, ymd("2021-01-15"), ymd_hms("2021-01-15 08:00:00"), +#' "STUDY01", "P01", "BID", 336, ymd("2021-01-15"), ymd_hms("2021-01-15 08:00:00"), #' ymd("2021-01-29"), ymd_hms("2021-01-29 20:00:00") #' ) #' diff --git a/R/derive_vars_transposed.R b/R/derive_vars_transposed.R index 1c04d9c7c3..3b167d9e90 100644 --- a/R/derive_vars_transposed.R +++ b/R/derive_vars_transposed.R @@ -226,33 +226,33 @@ derive_vars_transposed <- function(dataset, #' library(tibble) #' #' cm <- tribble( -#' ~USUBJID, ~CMGRPID, ~CMREFID, ~CMDECOD, -#' "BP40257-1001", "14", "1192056", "PARACETAMOL", -#' "BP40257-1001", "18", "2007001", "SOLUMEDROL", -#' "BP40257-1002", "19", "2791596", "SPIRONOLACTONE" +#' ~STUDYID, ~USUBJID, ~CMGRPID, ~CMREFID, ~CMDECOD, +#' "STUDY01", "BP40257-1001", "14", "1192056", "PARACETAMOL", +#' "STUDY01", "BP40257-1001", "18", "2007001", "SOLUMEDROL", +#' "STUDY01", "BP40257-1002", "19", "2791596", "SPIRONOLACTONE" #' ) #' facm <- tribble( -#' ~USUBJID, ~FAGRPID, ~FAREFID, ~FATESTCD, ~FASTRESC, -#' "BP40257-1001", "1", "1192056", "CMATC1CD", "N", -#' "BP40257-1001", "1", "1192056", "CMATC2CD", "N02", -#' "BP40257-1001", "1", "1192056", "CMATC3CD", "N02B", -#' "BP40257-1001", "1", "1192056", "CMATC4CD", "N02BE", -#' "BP40257-1001", "1", "2007001", "CMATC1CD", "D", -#' "BP40257-1001", "1", "2007001", "CMATC2CD", "D10", -#' "BP40257-1001", "1", "2007001", "CMATC3CD", "D10A", -#' "BP40257-1001", "1", "2007001", "CMATC4CD", "D10AA", -#' "BP40257-1001", "2", "2007001", "CMATC1CD", "D", -#' "BP40257-1001", "2", "2007001", "CMATC2CD", "D07", -#' "BP40257-1001", "2", "2007001", "CMATC3CD", "D07A", -#' "BP40257-1001", "2", "2007001", "CMATC4CD", "D07AA", -#' "BP40257-1001", "3", "2007001", "CMATC1CD", "H", -#' "BP40257-1001", "3", "2007001", "CMATC2CD", "H02", -#' "BP40257-1001", "3", "2007001", "CMATC3CD", "H02A", -#' "BP40257-1001", "3", "2007001", "CMATC4CD", "H02AB", -#' "BP40257-1002", "1", "2791596", "CMATC1CD", "C", -#' "BP40257-1002", "1", "2791596", "CMATC2CD", "C03", -#' "BP40257-1002", "1", "2791596", "CMATC3CD", "C03D", -#' "BP40257-1002", "1", "2791596", "CMATC4CD", "C03DA" +#' ~STUDYID, ~USUBJID, ~FAGRPID, ~FAREFID, ~FATESTCD, ~FASTRESC, +#' "STUDY01", "BP40257-1001", "1", "1192056", "CMATC1CD", "N", +#' "STUDY01", "BP40257-1001", "1", "1192056", "CMATC2CD", "N02", +#' "STUDY01", "BP40257-1001", "1", "1192056", "CMATC3CD", "N02B", +#' "STUDY01", "BP40257-1001", "1", "1192056", "CMATC4CD", "N02BE", +#' "STUDY01", "BP40257-1001", "1", "2007001", "CMATC1CD", "D", +#' "STUDY01", "BP40257-1001", "1", "2007001", "CMATC2CD", "D10", +#' "STUDY01", "BP40257-1001", "1", "2007001", "CMATC3CD", "D10A", +#' "STUDY01", "BP40257-1001", "1", "2007001", "CMATC4CD", "D10AA", +#' "STUDY01", "BP40257-1001", "2", "2007001", "CMATC1CD", "D", +#' "STUDY01", "BP40257-1001", "2", "2007001", "CMATC2CD", "D07", +#' "STUDY01", "BP40257-1001", "2", "2007001", "CMATC3CD", "D07A", +#' "STUDY01", "BP40257-1001", "2", "2007001", "CMATC4CD", "D07AA", +#' "STUDY01", "BP40257-1001", "3", "2007001", "CMATC1CD", "H", +#' "STUDY01", "BP40257-1001", "3", "2007001", "CMATC2CD", "H02", +#' "STUDY01", "BP40257-1001", "3", "2007001", "CMATC3CD", "H02A", +#' "STUDY01", "BP40257-1001", "3", "2007001", "CMATC4CD", "H02AB", +#' "STUDY01", "BP40257-1002", "1", "2791596", "CMATC1CD", "C", +#' "STUDY01", "BP40257-1002", "1", "2791596", "CMATC2CD", "C03", +#' "STUDY01", "BP40257-1002", "1", "2791596", "CMATC3CD", "C03D", +#' "STUDY01", "BP40257-1002", "1", "2791596", "CMATC4CD", "C03DA" #' ) #' #' derive_vars_atc(cm, facm) diff --git a/man/create_single_dose_dataset.Rd b/man/create_single_dose_dataset.Rd index 5cf64b359e..b99552c1d0 100644 --- a/man/create_single_dose_dataset.Rd +++ b/man/create_single_dose_dataset.Rd @@ -123,12 +123,12 @@ library(tibble) library(dplyr) data <- tribble( - ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, - "P01", "Q2D", ymd("2021-01-01"), ymd_hms("2021-01-01 10:30:00"), + ~STUDYID, ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, + "STUDY01", "P01", "Q2D", ymd("2021-01-01"), ymd_hms("2021-01-01 10:30:00"), ymd("2021-01-07"), ymd_hms("2021-01-07 11:30:00"), - "P01", "Q3D", ymd("2021-01-08"), ymd_hms("2021-01-08 12:00:00"), + "STUDY01", "P01", "Q3D", ymd("2021-01-08"), ymd_hms("2021-01-08 12:00:00"), ymd("2021-01-14"), ymd_hms("2021-01-14 14:00:00"), - "P01", "EVERY 2 WEEKS", ymd("2021-01-15"), ymd_hms("2021-01-15 09:57:00"), + "STUDY01", "P01", "EVERY 2 WEEKS", ymd("2021-01-15"), ymd_hms("2021-01-15 09:57:00"), ymd("2021-01-29"), ymd_hms("2021-01-29 10:57:00") ) @@ -143,10 +143,10 @@ custom_lookup <- tribble( ) data <- tribble( - ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, - "P01", "Q30MIN", ymd("2021-01-01"), ymd_hms("2021-01-01T06:00:00"), + ~STUDYID, ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, + "STUDY01", "P01", "Q30MIN", ymd("2021-01-01"), ymd_hms("2021-01-01T06:00:00"), ymd("2021-01-01"), ymd_hms("2021-01-01T07:00:00"), - "P02", "Q90MIN", ymd("2021-01-01"), ymd_hms("2021-01-01T06:00:00"), + "STUDY02", "P02", "Q90MIN", ymd("2021-01-01"), ymd_hms("2021-01-01T06:00:00"), ymd("2021-01-01"), ymd_hms("2021-01-01T09:00:00") ) @@ -159,12 +159,12 @@ create_single_dose_dataset(data, # Example with nominal time data <- tribble( - ~USUBJID, ~EXDOSFRQ, ~NFRLT, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, - "P01", "BID", 0, ymd("2021-01-01"), ymd_hms("2021-01-01 08:00:00"), + ~STUDYID, ~USUBJID, ~EXDOSFRQ, ~NFRLT, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, + "STUDY01", "P01", "BID", 0, ymd("2021-01-01"), ymd_hms("2021-01-01 08:00:00"), ymd("2021-01-07"), ymd_hms("2021-01-07 20:00:00"), - "P01", "BID", 168, ymd("2021-01-08"), ymd_hms("2021-01-08 08:00:00"), + "STUDY01", "P01", "BID", 168, ymd("2021-01-08"), ymd_hms("2021-01-08 08:00:00"), ymd("2021-01-14"), ymd_hms("2021-01-14 20:00:00"), - "P01", "BID", 336, ymd("2021-01-15"), ymd_hms("2021-01-15 08:00:00"), + "STUDY01", "P01", "BID", 336, ymd("2021-01-15"), ymd_hms("2021-01-15 08:00:00"), ymd("2021-01-29"), ymd_hms("2021-01-29 20:00:00") ) diff --git a/man/derive_vars_atc.Rd b/man/derive_vars_atc.Rd index c442d4988c..729b237f97 100644 --- a/man/derive_vars_atc.Rd +++ b/man/derive_vars_atc.Rd @@ -50,33 +50,33 @@ Add Anatomical Therapeutic Chemical class variables from \code{FACM} to \code{AD library(tibble) cm <- tribble( - ~USUBJID, ~CMGRPID, ~CMREFID, ~CMDECOD, - "BP40257-1001", "14", "1192056", "PARACETAMOL", - "BP40257-1001", "18", "2007001", "SOLUMEDROL", - "BP40257-1002", "19", "2791596", "SPIRONOLACTONE" + ~STUDYID, ~USUBJID, ~CMGRPID, ~CMREFID, ~CMDECOD, + "STUDY01", "BP40257-1001", "14", "1192056", "PARACETAMOL", + "STUDY01", "BP40257-1001", "18", "2007001", "SOLUMEDROL", + "STUDY01", "BP40257-1002", "19", "2791596", "SPIRONOLACTONE" ) facm <- tribble( - ~USUBJID, ~FAGRPID, ~FAREFID, ~FATESTCD, ~FASTRESC, - "BP40257-1001", "1", "1192056", "CMATC1CD", "N", - "BP40257-1001", "1", "1192056", "CMATC2CD", "N02", - "BP40257-1001", "1", "1192056", "CMATC3CD", "N02B", - "BP40257-1001", "1", "1192056", "CMATC4CD", "N02BE", - "BP40257-1001", "1", "2007001", "CMATC1CD", "D", - "BP40257-1001", "1", "2007001", "CMATC2CD", "D10", - "BP40257-1001", "1", "2007001", "CMATC3CD", "D10A", - "BP40257-1001", "1", "2007001", "CMATC4CD", "D10AA", - "BP40257-1001", "2", "2007001", "CMATC1CD", "D", - "BP40257-1001", "2", "2007001", "CMATC2CD", "D07", - "BP40257-1001", "2", "2007001", "CMATC3CD", "D07A", - "BP40257-1001", "2", "2007001", "CMATC4CD", "D07AA", - "BP40257-1001", "3", "2007001", "CMATC1CD", "H", - "BP40257-1001", "3", "2007001", "CMATC2CD", "H02", - "BP40257-1001", "3", "2007001", "CMATC3CD", "H02A", - "BP40257-1001", "3", "2007001", "CMATC4CD", "H02AB", - "BP40257-1002", "1", "2791596", "CMATC1CD", "C", - "BP40257-1002", "1", "2791596", "CMATC2CD", "C03", - "BP40257-1002", "1", "2791596", "CMATC3CD", "C03D", - "BP40257-1002", "1", "2791596", "CMATC4CD", "C03DA" + ~STUDYID, ~USUBJID, ~FAGRPID, ~FAREFID, ~FATESTCD, ~FASTRESC, + "STUDY01", "BP40257-1001", "1", "1192056", "CMATC1CD", "N", + "STUDY01", "BP40257-1001", "1", "1192056", "CMATC2CD", "N02", + "STUDY01", "BP40257-1001", "1", "1192056", "CMATC3CD", "N02B", + "STUDY01", "BP40257-1001", "1", "1192056", "CMATC4CD", "N02BE", + "STUDY01", "BP40257-1001", "1", "2007001", "CMATC1CD", "D", + "STUDY01", "BP40257-1001", "1", "2007001", "CMATC2CD", "D10", + "STUDY01", "BP40257-1001", "1", "2007001", "CMATC3CD", "D10A", + "STUDY01", "BP40257-1001", "1", "2007001", "CMATC4CD", "D10AA", + "STUDY01", "BP40257-1001", "2", "2007001", "CMATC1CD", "D", + "STUDY01", "BP40257-1001", "2", "2007001", "CMATC2CD", "D07", + "STUDY01", "BP40257-1001", "2", "2007001", "CMATC3CD", "D07A", + "STUDY01", "BP40257-1001", "2", "2007001", "CMATC4CD", "D07AA", + "STUDY01", "BP40257-1001", "3", "2007001", "CMATC1CD", "H", + "STUDY01", "BP40257-1001", "3", "2007001", "CMATC2CD", "H02", + "STUDY01", "BP40257-1001", "3", "2007001", "CMATC3CD", "H02A", + "STUDY01", "BP40257-1001", "3", "2007001", "CMATC4CD", "H02AB", + "STUDY01", "BP40257-1002", "1", "2791596", "CMATC1CD", "C", + "STUDY01", "BP40257-1002", "1", "2791596", "CMATC2CD", "C03", + "STUDY01", "BP40257-1002", "1", "2791596", "CMATC3CD", "C03D", + "STUDY01", "BP40257-1002", "1", "2791596", "CMATC4CD", "C03DA" ) derive_vars_atc(cm, facm) diff --git a/tests/testthat/_snaps/create_single_dose_dataset.md b/tests/testthat/_snaps/create_single_dose_dataset.md index a5fa5b8501..6484d124f7 100644 --- a/tests/testthat/_snaps/create_single_dose_dataset.md +++ b/tests/testthat/_snaps/create_single_dose_dataset.md @@ -11,7 +11,8 @@ Code create_single_dose_dataset(input, start_date = ADTSTD, keep_source_vars = exprs( - USUBJID, EXDOSFRQ, ADTSTD, ASTDTM, AENDT, AENDTM)) + !!!get_admiral_option("subject_keys"), EXDOSFRQ, ADTSTD, ASTDTM, AENDT, + AENDTM)) Condition Error in `create_single_dose_dataset()`: ! The argument `start_date` is expected to have a name ending with "---DT". diff --git a/tests/testthat/_snaps/derive_vars_transposed.md b/tests/testthat/_snaps/derive_vars_transposed.md index 13b2f73817..d26b5ad584 100644 --- a/tests/testthat/_snaps/derive_vars_transposed.md +++ b/tests/testthat/_snaps/derive_vars_transposed.md @@ -1,13 +1,14 @@ # derive_vars_transposed Test 3: filter merge dataset 'many-to-one' Code - derive_vars_transposed(dataset, dataset_merge, by_vars = exprs(USUBJID), - key_var = TESTCD, value_var = VALUE, filter = TESTCD == "T01", relationship = "many-to-one") + derive_vars_transposed(dataset, dataset_merge, by_vars = get_admiral_option( + "subject_keys"), key_var = TESTCD, value_var = VALUE, filter = TESTCD == + "T01", relationship = "many-to-one") Output - # A tibble: 3 x 3 - USUBJID VAR1 T01 - - 1 P01 3 31 - 2 P02 31 3 - 3 P03 42 NA + # A tibble: 3 x 4 + STUDYID USUBJID VAR1 T01 + + 1 STUDY01 P01 3 31 + 2 STUDY01 P02 31 3 + 3 STUDY01 P03 42 NA diff --git a/tests/testthat/test-create_single_dose_dataset.R b/tests/testthat/test-create_single_dose_dataset.R index e8898fa4c8..917db8fdcf 100644 --- a/tests/testthat/test-create_single_dose_dataset.R +++ b/tests/testthat/test-create_single_dose_dataset.R @@ -2,24 +2,24 @@ ## Test 1: Works as expected for Q*/EVERY * cases ---- test_that("create_single_dose_dataset Test 1: Works as expected for Q*/EVERY * cases", { input <- tibble::tribble( - ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~AENDT, - "P01", "Q2D", ymd("2021-01-01"), ymd("2021-01-07"), - "P01", "Q3D", ymd("2021-01-08"), ymd("2021-01-14"), - "P01", "EVERY 2 WEEKS", ymd("2021-01-15"), ymd("2021-01-29"), - "P02", "ONCE", ymd("2021-02-02"), ymd("2021-02-02") + ~STUDYID, ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~AENDT, + "STUDY01", "P01", "Q2D", ymd("2021-01-01"), ymd("2021-01-07"), + "STUDY01", "P01", "Q3D", ymd("2021-01-08"), ymd("2021-01-14"), + "STUDY01", "P01", "EVERY 2 WEEKS", ymd("2021-01-15"), ymd("2021-01-29"), + "STUDY01", "P02", "ONCE", ymd("2021-02-02"), ymd("2021-02-02") ) expected_output <- tibble::tribble( - ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~AENDT, - "P01", "ONCE", ymd("2021-01-01"), ymd("2021-01-01"), - "P01", "ONCE", ymd("2021-01-03"), ymd("2021-01-03"), - "P01", "ONCE", ymd("2021-01-05"), ymd("2021-01-05"), - "P01", "ONCE", ymd("2021-01-07"), ymd("2021-01-07"), - "P01", "ONCE", ymd("2021-01-08"), ymd("2021-01-08"), - "P01", "ONCE", ymd("2021-01-11"), ymd("2021-01-11"), - "P01", "ONCE", ymd("2021-01-14"), ymd("2021-01-14"), - "P01", "ONCE", ymd("2021-01-15"), ymd("2021-01-15"), - "P01", "ONCE", ymd("2021-01-29"), ymd("2021-01-29"), - "P02", "ONCE", ymd("2021-02-02"), ymd("2021-02-02") + ~STUDYID, ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~AENDT, + "STUDY01", "P01", "ONCE", ymd("2021-01-01"), ymd("2021-01-01"), + "STUDY01", "P01", "ONCE", ymd("2021-01-03"), ymd("2021-01-03"), + "STUDY01", "P01", "ONCE", ymd("2021-01-05"), ymd("2021-01-05"), + "STUDY01", "P01", "ONCE", ymd("2021-01-07"), ymd("2021-01-07"), + "STUDY01", "P01", "ONCE", ymd("2021-01-08"), ymd("2021-01-08"), + "STUDY01", "P01", "ONCE", ymd("2021-01-11"), ymd("2021-01-11"), + "STUDY01", "P01", "ONCE", ymd("2021-01-14"), ymd("2021-01-14"), + "STUDY01", "P01", "ONCE", ymd("2021-01-15"), ymd("2021-01-15"), + "STUDY01", "P01", "ONCE", ymd("2021-01-29"), ymd("2021-01-29"), + "STUDY01", "P02", "ONCE", ymd("2021-02-02"), ymd("2021-02-02") ) expect_dfs_equal( @@ -34,63 +34,63 @@ test_that("create_single_dose_dataset Test 1: Works as expected for Q*/EVERY * c ## Test 2: Works as expected for # TIMES PER cases ---- test_that("create_single_dose_dataset Test 2: Works as expected for # TIMES PER cases", { input <- tibble::tribble( - ~USUBJID, ~DOSFREQ, ~EXSTDT, ~EXSTDTM, ~EXENDT, ~EXENDTM, - "P01", "2 TIMES PER YEAR", + ~STUDYID, ~USUBJID, ~DOSFREQ, ~EXSTDT, ~EXSTDTM, ~EXENDT, ~EXENDTM, + "STUDY01", "P01", "2 TIMES PER YEAR", ymd("2021-01-01"), ymd_hms("2021-01-01 10:00:00"), ymd("2021-07-01"), ymd_hms("2021-07-01 10:00:00"), - "P02", "2 TIMES PER YEAR", + "STUDY01", "P02", "2 TIMES PER YEAR", ymd("2021-01-01"), ymd_hms("2021-01-01 10:30:00"), ymd("2021-12-31"), ymd_hms("2021-12-31 10:30:00"), - "P03", "4 TIMES PER MONTH", + "STUDY01", "P03", "4 TIMES PER MONTH", ymd("2021-02-01"), ymd_hms("2021-02-01 11:00:00"), ymd("2021-03-01"), ymd_hms("2021-03-01 11:00:00"), - "P04", "4 TIMES PER MONTH", + "STUDY01", "P04", "4 TIMES PER MONTH", ymd("2021-01-01"), ymd_hms("2021-01-01 11:30:00"), ymd("2021-01-20"), ymd_hms("2021-01-20 11:30:00"), - "P05", "5 TIMES PER WEEK", + "STUDY01", "P05", "5 TIMES PER WEEK", ymd("2021-01-15"), ymd_hms("2021-01-15 12:00:00"), ymd("2021-01-17"), ymd_hms("2021-01-17 12:00:00"), - "P06", "5 TIMES PER WEEK", + "STUDY01", "P06", "5 TIMES PER WEEK", ymd("2021-01-15"), ymd_hms("2021-01-15 12:30:00"), ymd("2021-01-21"), ymd_hms("2021-01-21 12:30:00"), ) expected_output <- tibble::tribble( - ~USUBJID, ~DOSFREQ, ~EXSTDT, ~EXSTDTM, ~EXENDT, ~EXENDTM, - "P01", "ONCE", ymd("2021-01-01"), ymd_hms("2021-01-01 10:00:00"), + ~STUDYID, ~USUBJID, ~DOSFREQ, ~EXSTDT, ~EXSTDTM, ~EXENDT, ~EXENDTM, + "STUDY01", "P01", "ONCE", ymd("2021-01-01"), ymd_hms("2021-01-01 10:00:00"), ymd("2021-01-01"), ymd_hms("2021-01-01 10:00:00"), - "P02", "ONCE", ymd("2021-01-01"), ymd_hms("2021-01-01 10:30:00"), + "STUDY01", "P02", "ONCE", ymd("2021-01-01"), ymd_hms("2021-01-01 10:30:00"), ymd("2021-01-01"), ymd_hms("2021-01-01 10:30:00"), - "P02", "ONCE", ymd("2021-07-02"), ymd_hms("2021-07-02 10:30:00"), + "STUDY01", "P02", "ONCE", ymd("2021-07-02"), ymd_hms("2021-07-02 10:30:00"), ymd("2021-07-02"), ymd_hms("2021-07-02 10:30:00"), - "P03", "ONCE", ymd("2021-02-01"), ymd_hms("2021-02-01 11:00:00"), + "STUDY01", "P03", "ONCE", ymd("2021-02-01"), ymd_hms("2021-02-01 11:00:00"), ymd("2021-02-01"), ymd_hms("2021-02-01 11:00:00"), - "P03", "ONCE", ymd("2021-02-08"), ymd_hms("2021-02-08 11:00:00"), + "STUDY01", "P03", "ONCE", ymd("2021-02-08"), ymd_hms("2021-02-08 11:00:00"), ymd("2021-02-08"), ymd_hms("2021-02-08 11:00:00"), - "P03", "ONCE", ymd("2021-02-16"), ymd_hms("2021-02-16 11:00:00"), + "STUDY01", "P03", "ONCE", ymd("2021-02-16"), ymd_hms("2021-02-16 11:00:00"), ymd("2021-02-16"), ymd_hms("2021-02-16 11:00:00"), - "P03", "ONCE", ymd("2021-02-23"), ymd_hms("2021-02-23 11:00:00"), + "STUDY01", "P03", "ONCE", ymd("2021-02-23"), ymd_hms("2021-02-23 11:00:00"), ymd("2021-02-23"), ymd_hms("2021-02-23 11:00:00"), - "P04", "ONCE", ymd("2021-01-01"), ymd_hms("2021-01-01 11:30:00"), + "STUDY01", "P04", "ONCE", ymd("2021-01-01"), ymd_hms("2021-01-01 11:30:00"), ymd("2021-01-01"), ymd_hms("2021-01-01 11:30:00"), - "P04", "ONCE", ymd("2021-01-08"), ymd_hms("2021-01-08 11:30:00"), + "STUDY01", "P04", "ONCE", ymd("2021-01-08"), ymd_hms("2021-01-08 11:30:00"), ymd("2021-01-08"), ymd_hms("2021-01-08 11:30:00"), - "P04", "ONCE", ymd("2021-01-16"), ymd_hms("2021-01-16 11:30:00"), + "STUDY01", "P04", "ONCE", ymd("2021-01-16"), ymd_hms("2021-01-16 11:30:00"), ymd("2021-01-16"), ymd_hms("2021-01-16 11:30:00"), - "P05", "ONCE", ymd("2021-01-15"), ymd_hms("2021-01-15 12:00:00"), + "STUDY01", "P05", "ONCE", ymd("2021-01-15"), ymd_hms("2021-01-15 12:00:00"), ymd("2021-01-15"), ymd_hms("2021-01-15 12:00:00"), - "P05", "ONCE", ymd("2021-01-16"), ymd_hms("2021-01-16 12:00:00"), + "STUDY01", "P05", "ONCE", ymd("2021-01-16"), ymd_hms("2021-01-16 12:00:00"), ymd("2021-01-16"), ymd_hms("2021-01-16 12:00:00"), - "P05", "ONCE", ymd("2021-01-17"), ymd_hms("2021-01-17 12:00:00"), + "STUDY01", "P05", "ONCE", ymd("2021-01-17"), ymd_hms("2021-01-17 12:00:00"), ymd("2021-01-17"), ymd_hms("2021-01-17 12:00:00"), - "P06", "ONCE", ymd("2021-01-15"), ymd_hms("2021-01-15 12:30:00"), + "STUDY01", "P06", "ONCE", ymd("2021-01-15"), ymd_hms("2021-01-15 12:30:00"), ymd("2021-01-15"), ymd_hms("2021-01-15 12:30:00"), - "P06", "ONCE", ymd("2021-01-16"), ymd_hms("2021-01-16 12:30:00"), + "STUDY01", "P06", "ONCE", ymd("2021-01-16"), ymd_hms("2021-01-16 12:30:00"), ymd("2021-01-16"), ymd_hms("2021-01-16 12:30:00"), - "P06", "ONCE", ymd("2021-01-17"), ymd_hms("2021-01-17 12:30:00"), + "STUDY01", "P06", "ONCE", ymd("2021-01-17"), ymd_hms("2021-01-17 12:30:00"), ymd("2021-01-17"), ymd_hms("2021-01-17 12:30:00"), - "P06", "ONCE", ymd("2021-01-19"), ymd_hms("2021-01-19 12:30:00"), + "STUDY01", "P06", "ONCE", ymd("2021-01-19"), ymd_hms("2021-01-19 12:30:00"), ymd("2021-01-19"), ymd_hms("2021-01-19 12:30:00"), - "P06", "ONCE", ymd("2021-01-20"), ymd_hms("2021-01-20 12:30:00"), + "STUDY01", "P06", "ONCE", ymd("2021-01-20"), ymd_hms("2021-01-20 12:30:00"), ymd("2021-01-20"), ymd_hms("2021-01-20 12:30:00") ) @@ -111,23 +111,23 @@ test_that("create_single_dose_dataset Test 2: Works as expected for # TIMES PER ## Test 3: Works for different treatments ---- test_that("create_single_dose_dataset Test 3: Works for different treatments", { input <- tibble::tribble( - ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, ~EXTRT, - "P01", "Q2D", ymd("2021-01-01"), ymd_hms("2021-01-01 09:00:00"), + ~STUDYID, ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, ~EXTRT, + "STUDY01", "P01", "Q2D", ymd("2021-01-01"), ymd_hms("2021-01-01 09:00:00"), ymd("2021-01-03"), ymd_hms("2021-01-03 09:00:00"), "XANOMELINE", - "P01", "QOD", ymd("2021-01-01"), ymd_hms("2021-01-01 09:15:00"), + "STUDY01", "P01", "QOD", ymd("2021-01-01"), ymd_hms("2021-01-01 09:15:00"), ymd("2021-01-05"), ymd_hms("2021-01-05 09:15:00"), "PLACEBO" ) expected_output <- tibble::tribble( - ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, ~EXTRT, - "P01", "ONCE", ymd("2021-01-01"), ymd_hms("2021-01-01 09:00:00"), + ~STUDYID, ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, ~EXTRT, + "STUDY01", "P01", "ONCE", ymd("2021-01-01"), ymd_hms("2021-01-01 09:00:00"), ymd("2021-01-01"), ymd_hms("2021-01-01 09:00:00"), "XANOMELINE", - "P01", "ONCE", ymd("2021-01-03"), ymd_hms("2021-01-03 09:00:00"), + "STUDY01", "P01", "ONCE", ymd("2021-01-03"), ymd_hms("2021-01-03 09:00:00"), ymd("2021-01-03"), ymd_hms("2021-01-03 09:00:00"), "XANOMELINE", - "P01", "ONCE", ymd("2021-01-01"), ymd_hms("2021-01-01 09:15:00"), + "STUDY01", "P01", "ONCE", ymd("2021-01-01"), ymd_hms("2021-01-01 09:15:00"), ymd("2021-01-01"), ymd_hms("2021-01-01 09:15:00"), "PLACEBO", - "P01", "ONCE", ymd("2021-01-03"), ymd_hms("2021-01-03 09:15:00"), + "STUDY01", "P01", "ONCE", ymd("2021-01-03"), ymd_hms("2021-01-03 09:15:00"), ymd("2021-01-03"), ymd_hms("2021-01-03 09:15:00"), "PLACEBO", - "P01", "ONCE", ymd("2021-01-05"), ymd_hms("2021-01-05 09:15:00"), + "STUDY01", "P01", "ONCE", ymd("2021-01-05"), ymd_hms("2021-01-05 09:15:00"), ymd("2021-01-05"), ymd_hms("2021-01-05 09:15:00"), "PLACEBO" ) @@ -136,7 +136,8 @@ test_that("create_single_dose_dataset Test 3: Works for different treatments", { input, start_datetime = ASTDTM, end_datetime = AENDTM, - keep_source_vars = exprs(USUBJID, EXDOSFRQ, ASTDT, ASTDTM, AENDT, AENDTM, EXTRT) + keep_source_vars = exprs(!!!get_admiral_option("subject_keys"), + EXDOSFRQ, ASTDT, ASTDTM, AENDT, AENDTM, EXTRT) ), expected_output, keys = c("EXTRT", "ASTDT") @@ -152,26 +153,26 @@ test_that("create_single_dose_dataset Test 4: Custom lookup works", { ) input <- tibble::tribble( - ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, - "P01", "Q30MIN", ymd("2021-01-01"), ymd_hms("2021-01-01T06:00:00"), + ~STUDYID, ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, + "STUDY01", "P01", "Q30MIN", ymd("2021-01-01"), ymd_hms("2021-01-01T06:00:00"), ymd("2021-01-01"), ymd_hms("2021-01-01T07:00:00"), - "P02", "Q90MIN", ymd("2021-01-01"), ymd_hms("2021-01-01T06:00:00"), + "STUDY01", "P02", "Q90MIN", ymd("2021-01-01"), ymd_hms("2021-01-01T06:00:00"), ymd("2021-01-01"), ymd_hms("2021-01-01T09:00:00") ) expected_output <- tibble::tribble( - ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, - "P01", "ONCE", ymd("2021-01-01"), ymd_hms("2021-01-01T06:00:00"), + ~STUDYID, ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, + "STUDY01", "P01", "ONCE", ymd("2021-01-01"), ymd_hms("2021-01-01T06:00:00"), ymd("2021-01-01"), ymd_hms("2021-01-01T06:00:00"), - "P01", "ONCE", ymd("2021-01-01"), ymd_hms("2021-01-01T06:30:00"), + "STUDY01", "P01", "ONCE", ymd("2021-01-01"), ymd_hms("2021-01-01T06:30:00"), ymd("2021-01-01"), ymd_hms("2021-01-01T06:30:00"), - "P01", "ONCE", ymd("2021-01-01"), ymd_hms("2021-01-01T07:00:00"), + "STUDY01", "P01", "ONCE", ymd("2021-01-01"), ymd_hms("2021-01-01T07:00:00"), ymd("2021-01-01"), ymd_hms("2021-01-01T07:00:00"), - "P02", "ONCE", ymd("2021-01-01"), ymd_hms("2021-01-01T06:00:00"), + "STUDY01", "P02", "ONCE", ymd("2021-01-01"), ymd_hms("2021-01-01T06:00:00"), ymd("2021-01-01"), ymd_hms("2021-01-01T06:00:00"), - "P02", "ONCE", ymd("2021-01-01"), ymd_hms("2021-01-01T07:30:00"), + "STUDY01", "P02", "ONCE", ymd("2021-01-01"), ymd_hms("2021-01-01T07:30:00"), ymd("2021-01-01"), ymd_hms("2021-01-01T07:30:00"), - "P02", "ONCE", ymd("2021-01-01"), ymd_hms("2021-01-01T09:00:00"), + "STUDY01", "P02", "ONCE", ymd("2021-01-01"), ymd_hms("2021-01-01T09:00:00"), ymd("2021-01-01"), ymd_hms("2021-01-01T09:00:00") ) @@ -191,12 +192,12 @@ test_that("create_single_dose_dataset Test 4: Custom lookup works", { ## Test 5: Warning is returned when values in EXDOSFRQ does not appear in lookup table ---- test_that("create_single_dose_dataset Test 5: Warning is returned when values in EXDOSFRQ does not appear in lookup table", { # nolint input <- tibble::tribble( - ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, - "P01", "1", ymd("2021-01-01"), ymd_hms("2021-01-01T09:00:00"), + ~STUDYID, ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, + "STUDY01", "P01", "1", ymd("2021-01-01"), ymd_hms("2021-01-01T09:00:00"), ymd("2021-01-03"), ymd_hms("2021-01-03T09:00:00"), - "P01", "1", ymd("2021-01-08"), ymd_hms("2021-01-08T09:00:00"), + "STUDY01", "P01", "1", ymd("2021-01-08"), ymd_hms("2021-01-08T09:00:00"), ymd("2021-01-12"), ymd_hms("2021-01-12T09:00:00"), - "P01", "1", ymd("2021-01-15"), ymd_hms("2021-01-15T09:00:00"), + "STUDY01", "P01", "1", ymd("2021-01-15"), ymd_hms("2021-01-15T09:00:00"), ymd("2021-01-29"), ymd_hms("2021-01-29T09:00:00") ) expect_error( @@ -207,11 +208,11 @@ test_that("create_single_dose_dataset Test 5: Warning is returned when values in ## Test 6: Error when a date variable contains NA values ---- test_that("create_single_dose_dataset Test 6: Error when a date variable contains NA values", { input <- tibble::tribble( - ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, - "P01", "Q2D", ymd("2021-01-01"), ymd_hms("2021-01-01T09:00:00"), NA, NA, - "P01", "Q3D", ymd("2021-01-08"), ymd_hms("2021-01-08T09:00:00"), + ~STUDYID, ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, + "STUDY01", "P01", "Q2D", ymd("2021-01-01"), ymd_hms("2021-01-01T09:00:00"), NA, NA, + "STUDY01", "P01", "Q3D", ymd("2021-01-08"), ymd_hms("2021-01-08T09:00:00"), ymd("2021-01-15"), ymd_hms("2021-01-15T09:00:00"), - "P01", "EVERY 2 WEEKS", ymd("2021-01-15"), ymd_hms("2021-01-15T09:00:00"), + "STUDY01", "P01", "EVERY 2 WEEKS", ymd("2021-01-15"), ymd_hms("2021-01-15T09:00:00"), ymd("2021-01-29"), ymd_hms("2021-01-29T09:00:00") ) expect_snapshot( @@ -223,12 +224,12 @@ test_that("create_single_dose_dataset Test 6: Error when a date variable contain ## Test 7: Message for improper DT column names, ASTDT ---- test_that("create_single_dose_dataset Test 7: Message for improper DT column names, ASTDT", { input <- tibble::tribble( - ~USUBJID, ~EXDOSFRQ, ~ADTSTD, ~ASTDTM, ~AENDT, ~AENDTM, - "P01", "Q2D", ymd("2021-01-01"), ymd_hms("2021-01-01 10:30:00"), + ~STUDYID, ~USUBJID, ~EXDOSFRQ, ~ADTSTD, ~ASTDTM, ~AENDT, ~AENDTM, + "STUDY01", "P01", "Q2D", ymd("2021-01-01"), ymd_hms("2021-01-01 10:30:00"), ymd("2021-01-07"), ymd_hms("2021-01-07 11:30:00"), - "P01", "Q3D", ymd("2021-01-01"), ymd_hms("2021-01-08 12:00:00"), + "STUDY01", "P01", "Q3D", ymd("2021-01-01"), ymd_hms("2021-01-08 12:00:00"), ymd("2021-01-14"), ymd_hms("2021-01-14 14:00:00"), - "P01", "EVERY 2 WEEKS", ymd("2021-01-15"), ymd_hms("2021-01-15 09:57:00"), + "STUDY01", "P01", "EVERY 2 WEEKS", ymd("2021-01-15"), ymd_hms("2021-01-15 09:57:00"), ymd("2021-01-29"), ymd_hms("2021-01-29 10:57:00") ) expect_snapshot( @@ -236,7 +237,7 @@ test_that("create_single_dose_dataset Test 7: Message for improper DT column nam create_single_dose_dataset(input, start_date = ADTSTD, keep_source_vars = exprs( - USUBJID, EXDOSFRQ, + !!!get_admiral_option("subject_keys"), EXDOSFRQ, ADTSTD, ASTDTM, AENDT, AENDTM ) @@ -247,12 +248,12 @@ test_that("create_single_dose_dataset Test 7: Message for improper DT column nam ## Test 8: Message for improper DT column names, AENDT ---- test_that("create_single_dose_dataset Test 8: Message for improper DT column names, AENDT", { input <- tibble::tribble( - ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~ASTDTM, ~ADTEND, ~AENDTM, - "P01", "Q2D", ymd("2021-01-01"), ymd_hms("2021-01-01 10:30:00"), + ~STUDYID, ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~ASTDTM, ~ADTEND, ~AENDTM, + "STUDY01", "P01", "Q2D", ymd("2021-01-01"), ymd_hms("2021-01-01 10:30:00"), ymd("2021-01-07"), ymd_hms("2021-01-07 11:30:00"), - "P01", "Q3D", ymd("2021-01-01"), ymd_hms("2021-01-08 12:00:00"), + "STUDY01", "P01", "Q3D", ymd("2021-01-01"), ymd_hms("2021-01-08 12:00:00"), ymd("2021-01-14"), ymd_hms("2021-01-14 14:00:00"), - "P01", "EVERY 2 WEEKS", ymd("2021-01-15"), ymd_hms("2021-01-15 09:57:00"), + "STUDY01", "P01", "EVERY 2 WEEKS", ymd("2021-01-15"), ymd_hms("2021-01-15 09:57:00"), ymd("2021-01-29"), ymd_hms("2021-01-29 10:57:00") ) expect_snapshot( @@ -266,9 +267,9 @@ test_that("create_single_dose_dataset Test 8: Message for improper DT column nam ## Test 9: error if no datetime and freq more than QD ---- test_that("create_single_dose_dataset Test 9: error if no datetime and freq more than QD", { input <- tibble::tribble( - ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~AENDT, - "P01", "Q12H", ymd("2021-01-01"), ymd("2021-01-01"), - "P02", "Q12H", ymd("2021-01-01"), ymd("2021-01-01") + ~STUDYID, ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~AENDT, + "STUDY01", "P01", "Q12H", ymd("2021-01-01"), ymd("2021-01-01"), + "STUDY01", "P02", "Q12H", ymd("2021-01-01"), ymd("2021-01-01") ) expect_snapshot( @@ -280,37 +281,37 @@ test_that("create_single_dose_dataset Test 9: error if no datetime and freq more ## Test 10: Works as expected for BID cases ---- test_that("create_single_dose_dataset Test 10: Works as expected for BID cases", { input <- tibble::tribble( - ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, - "P01", "BID", ymd("2021-01-01"), ymd_hms("2021-01-01 08:00:00"), + ~STUDYID, ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, + "STUDY01", "P01", "BID", ymd("2021-01-01"), ymd_hms("2021-01-01 08:00:00"), ymd("2021-01-03"), ymd_hms("2021-01-03 20:00:00"), - "P01", "BID", ymd("2021-01-04"), ymd_hms("2021-01-04 08:00:00"), + "STUDY01", "P01", "BID", ymd("2021-01-04"), ymd_hms("2021-01-04 08:00:00"), ymd("2021-01-06"), ymd_hms("2021-01-06 20:00:00") ) expected_output <- tibble::tribble( - ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, - "P01", "ONCE", ymd("2021-01-01"), ymd_hms("2021-01-01 08:00:00"), + ~STUDYID, ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, + "STUDY01", "P01", "ONCE", ymd("2021-01-01"), ymd_hms("2021-01-01 08:00:00"), ymd("2021-01-01"), ymd_hms("2021-01-01 08:00:00"), - "P01", "ONCE", ymd("2021-01-01"), ymd_hms("2021-01-01 20:00:00"), + "STUDY01", "P01", "ONCE", ymd("2021-01-01"), ymd_hms("2021-01-01 20:00:00"), ymd("2021-01-01"), ymd_hms("2021-01-01 20:00:00"), - "P01", "ONCE", ymd("2021-01-02"), ymd_hms("2021-01-02 08:00:00"), + "STUDY01", "P01", "ONCE", ymd("2021-01-02"), ymd_hms("2021-01-02 08:00:00"), ymd("2021-01-02"), ymd_hms("2021-01-02 08:00:00"), - "P01", "ONCE", ymd("2021-01-02"), ymd_hms("2021-01-02 20:00:00"), + "STUDY01", "P01", "ONCE", ymd("2021-01-02"), ymd_hms("2021-01-02 20:00:00"), ymd("2021-01-02"), ymd_hms("2021-01-02 20:00:00"), - "P01", "ONCE", ymd("2021-01-03"), ymd_hms("2021-01-03 08:00:00"), + "STUDY01", "P01", "ONCE", ymd("2021-01-03"), ymd_hms("2021-01-03 08:00:00"), ymd("2021-01-03"), ymd_hms("2021-01-03 08:00:00"), - "P01", "ONCE", ymd("2021-01-03"), ymd_hms("2021-01-03 20:00:00"), + "STUDY01", "P01", "ONCE", ymd("2021-01-03"), ymd_hms("2021-01-03 20:00:00"), ymd("2021-01-03"), ymd_hms("2021-01-03 20:00:00"), - "P01", "ONCE", ymd("2021-01-04"), ymd_hms("2021-01-04 08:00:00"), + "STUDY01", "P01", "ONCE", ymd("2021-01-04"), ymd_hms("2021-01-04 08:00:00"), ymd("2021-01-04"), ymd_hms("2021-01-04 08:00:00"), - "P01", "ONCE", ymd("2021-01-04"), ymd_hms("2021-01-04 20:00:00"), + "STUDY01", "P01", "ONCE", ymd("2021-01-04"), ymd_hms("2021-01-04 20:00:00"), ymd("2021-01-04"), ymd_hms("2021-01-04 20:00:00"), - "P01", "ONCE", ymd("2021-01-05"), ymd_hms("2021-01-05 08:00:00"), + "STUDY01", "P01", "ONCE", ymd("2021-01-05"), ymd_hms("2021-01-05 08:00:00"), ymd("2021-01-05"), ymd_hms("2021-01-05 08:00:00"), - "P01", "ONCE", ymd("2021-01-05"), ymd_hms("2021-01-05 20:00:00"), + "STUDY01", "P01", "ONCE", ymd("2021-01-05"), ymd_hms("2021-01-05 20:00:00"), ymd("2021-01-05"), ymd_hms("2021-01-05 20:00:00"), - "P01", "ONCE", ymd("2021-01-06"), ymd_hms("2021-01-06 08:00:00"), + "STUDY01", "P01", "ONCE", ymd("2021-01-06"), ymd_hms("2021-01-06 08:00:00"), ymd("2021-01-06"), ymd_hms("2021-01-06 08:00:00"), - "P01", "ONCE", ymd("2021-01-06"), ymd_hms("2021-01-06 20:00:00"), + "STUDY01", "P01", "ONCE", ymd("2021-01-06"), ymd_hms("2021-01-06 20:00:00"), ymd("2021-01-06"), ymd_hms("2021-01-06 20:00:00"), ) @@ -325,7 +326,7 @@ test_that("create_single_dose_dataset Test 10: Works as expected for BID cases", lookup_table = dose_freq_lookup, lookup_column = CDISC_VALUE, keep_source_vars = exprs( - USUBJID, EXDOSFRQ, ASTDT, ASTDTM, AENDT, AENDTM + !!!get_admiral_option("subject_keys"), EXDOSFRQ, ASTDT, ASTDTM, AENDT, AENDTM ) ), expected_output, @@ -336,41 +337,41 @@ test_that("create_single_dose_dataset Test 10: Works as expected for BID cases", ## Test 11: Works as expected for cases with nominal time ---- test_that("create_single_dose_dataset Test 11: Works as expected for cases with nominal time", { input <- tibble::tribble( - ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, ~NFRLT, - "P01", "QD", ymd("2021-01-01"), ymd_hms("2021-01-01 08:00:00"), + ~STUDYID, ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, ~NFRLT, + "STUDY01", "P01", "QD", ymd("2021-01-01"), ymd_hms("2021-01-01 08:00:00"), ymd("2021-01-07"), ymd_hms("2021-01-07 08:00:00"), 0, - "P01", "QD", ymd("2021-01-08"), ymd_hms("2021-01-08 08:00:00"), + "STUDY01", "P01", "QD", ymd("2021-01-08"), ymd_hms("2021-01-08 08:00:00"), ymd("2021-01-14"), ymd_hms("2021-01-14 08:00:00"), 168 ) expected_output <- tibble::tribble( - ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, ~NFRLT, - "P01", "ONCE", ymd("2021-01-01"), ymd_hms("2021-01-01 08:00:00"), + ~STUDYID, ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, ~NFRLT, + "STUDY01", "P01", "ONCE", ymd("2021-01-01"), ymd_hms("2021-01-01 08:00:00"), ymd("2021-01-01"), ymd_hms("2021-01-01 08:00:00"), 0, - "P01", "ONCE", ymd("2021-01-02"), ymd_hms("2021-01-02 08:00:00"), + "STUDY01", "P01", "ONCE", ymd("2021-01-02"), ymd_hms("2021-01-02 08:00:00"), ymd("2021-01-02"), ymd_hms("2021-01-02 08:00:00"), 24, - "P01", "ONCE", ymd("2021-01-03"), ymd_hms("2021-01-03 08:00:00"), + "STUDY01", "P01", "ONCE", ymd("2021-01-03"), ymd_hms("2021-01-03 08:00:00"), ymd("2021-01-03"), ymd_hms("2021-01-03 08:00:00"), 48, - "P01", "ONCE", ymd("2021-01-04"), ymd_hms("2021-01-04 08:00:00"), + "STUDY01", "P01", "ONCE", ymd("2021-01-04"), ymd_hms("2021-01-04 08:00:00"), ymd("2021-01-04"), ymd_hms("2021-01-04 08:00:00"), 72, - "P01", "ONCE", ymd("2021-01-05"), ymd_hms("2021-01-05 08:00:00"), + "STUDY01", "P01", "ONCE", ymd("2021-01-05"), ymd_hms("2021-01-05 08:00:00"), ymd("2021-01-05"), ymd_hms("2021-01-05 08:00:00"), 96, - "P01", "ONCE", ymd("2021-01-06"), ymd_hms("2021-01-06 08:00:00"), + "STUDY01", "P01", "ONCE", ymd("2021-01-06"), ymd_hms("2021-01-06 08:00:00"), ymd("2021-01-06"), ymd_hms("2021-01-06 08:00:00"), 120, - "P01", "ONCE", ymd("2021-01-07"), ymd_hms("2021-01-07 08:00:00"), + "STUDY01", "P01", "ONCE", ymd("2021-01-07"), ymd_hms("2021-01-07 08:00:00"), ymd("2021-01-07"), ymd_hms("2021-01-07 08:00:00"), 144, - "P01", "ONCE", ymd("2021-01-08"), ymd_hms("2021-01-08 08:00:00"), + "STUDY01", "P01", "ONCE", ymd("2021-01-08"), ymd_hms("2021-01-08 08:00:00"), ymd("2021-01-08"), ymd_hms("2021-01-08 08:00:00"), 168, - "P01", "ONCE", ymd("2021-01-09"), ymd_hms("2021-01-09 08:00:00"), + "STUDY01", "P01", "ONCE", ymd("2021-01-09"), ymd_hms("2021-01-09 08:00:00"), ymd("2021-01-09"), ymd_hms("2021-01-09 08:00:00"), 192, - "P01", "ONCE", ymd("2021-01-10"), ymd_hms("2021-01-10 08:00:00"), + "STUDY01", "P01", "ONCE", ymd("2021-01-10"), ymd_hms("2021-01-10 08:00:00"), ymd("2021-01-10"), ymd_hms("2021-01-10 08:00:00"), 216, - "P01", "ONCE", ymd("2021-01-11"), ymd_hms("2021-01-11 08:00:00"), + "STUDY01", "P01", "ONCE", ymd("2021-01-11"), ymd_hms("2021-01-11 08:00:00"), ymd("2021-01-11"), ymd_hms("2021-01-11 08:00:00"), 240, - "P01", "ONCE", ymd("2021-01-12"), ymd_hms("2021-01-12 08:00:00"), + "STUDY01", "P01", "ONCE", ymd("2021-01-12"), ymd_hms("2021-01-12 08:00:00"), ymd("2021-01-12"), ymd_hms("2021-01-12 08:00:00"), 264, - "P01", "ONCE", ymd("2021-01-13"), ymd_hms("2021-01-13 08:00:00"), + "STUDY01", "P01", "ONCE", ymd("2021-01-13"), ymd_hms("2021-01-13 08:00:00"), ymd("2021-01-13"), ymd_hms("2021-01-13 08:00:00"), 288, - "P01", "ONCE", ymd("2021-01-14"), ymd_hms("2021-01-14 08:00:00"), + "STUDY01", "P01", "ONCE", ymd("2021-01-14"), ymd_hms("2021-01-14 08:00:00"), ymd("2021-01-14"), ymd_hms("2021-01-14 08:00:00"), 312, ) @@ -386,7 +387,7 @@ test_that("create_single_dose_dataset Test 11: Works as expected for cases with lookup_column = CDISC_VALUE, nominal_time = NFRLT, keep_source_vars = exprs( - USUBJID, EXDOSFRQ, ASTDT, ASTDTM, AENDT, AENDTM, NFRLT + !!!get_admiral_option("subject_keys"), EXDOSFRQ, ASTDT, ASTDTM, AENDT, AENDTM, NFRLT ) ), expected_output, @@ -404,10 +405,10 @@ test_that("create_single_dose_dataset Test 12: Error if lookup_column contains d ) input <- tribble( - ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, - "P01", "Q30MIN", ymd("2021-01-01"), ymd_hms("2021-01-01T06:00:00"), + ~STUDYID, ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~ASTDTM, ~AENDT, ~AENDTM, + "STUDY01", "P01", "Q30MIN", ymd("2021-01-01"), ymd_hms("2021-01-01T06:00:00"), ymd("2021-01-01"), ymd_hms("2021-01-01T07:00:00"), - "P02", "Q90MIN", ymd("2021-01-01"), ymd_hms("2021-01-01T06:00:00"), + "STUDY01", "P02", "Q90MIN", ymd("2021-01-01"), ymd_hms("2021-01-01T06:00:00"), ymd("2021-01-01"), ymd_hms("2021-01-01T09:00:00") ) diff --git a/tests/testthat/test-derive_vars_transposed.R b/tests/testthat/test-derive_vars_transposed.R index b25ab9fd1b..6472afba9f 100644 --- a/tests/testthat/test-derive_vars_transposed.R +++ b/tests/testthat/test-derive_vars_transposed.R @@ -1,29 +1,29 @@ dataset <- tibble::tribble( - ~USUBJID, ~VAR1, - "P01", 3, - "P02", 31, - "P03", 42 + ~STUDYID, ~USUBJID, ~VAR1, + "STUDY01", "P01", 3, + "STUDY01", "P02", 31, + "STUDY01", "P03", 42 ) dataset_merge <- tibble::tribble( - ~USUBJID, ~TESTCD, ~VALUE, - "P01", "T01", 31, - "P01", "T02", 5, - "P02", "T01", 3, - "P03", "T02", 9 + ~STUDYID, ~USUBJID, ~TESTCD, ~VALUE, + "STUDY01", "P01", "T01", 31, + "STUDY01", "P01", "T02", 5, + "STUDY01", "P02", "T01", 3, + "STUDY01", "P03", "T02", 9 ) ## Test 1: the merge dataset is transposed and merged correctly ---- test_that("derive_vars_transposed Test 1: the merge dataset is transposed and merged correctly", { expected_output <- tibble::tribble( - ~USUBJID, ~VAR1, ~T01, ~T02, - "P01", 3, 31, 5, - "P02", 31, 3, NA, - "P03", 42, NA, 9 + ~STUDYID, ~USUBJID, ~VAR1, ~T01, ~T02, + "STUDY01", "P01", 3, 31, 5, + "STUDY01", "P02", 31, 3, NA, + "STUDY01", "P03", 42, NA, 9 ) actual_output <- derive_vars_transposed( dataset, dataset_merge, - by_vars = exprs(USUBJID), + by_vars = get_admiral_option("subject_keys"), key_var = TESTCD, value_var = VALUE ) @@ -35,15 +35,15 @@ test_that("derive_vars_transposed Test 1: the merge dataset is transposed and me ## Test 2: filtering the merge dataset works ---- test_that("derive_vars_transposed Test 2: filtering the merge dataset works", { expected_output <- tibble::tribble( - ~USUBJID, ~VAR1, ~T01, - "P01", 3, 31, - "P02", 31, 3, - "P03", 42, NA + ~STUDYID, ~USUBJID, ~VAR1, ~T01, + "STUDY01", "P01", 3, 31, + "STUDY01", "P02", 31, 3, + "STUDY01", "P03", 42, NA ) actual_output <- derive_vars_transposed( dataset, dataset_merge, - by_vars = exprs(USUBJID), + by_vars = get_admiral_option("subject_keys"), key_var = TESTCD, value_var = VALUE, filter = TESTCD == "T01" @@ -58,7 +58,7 @@ test_that("derive_vars_transposed Test 3: filter merge dataset 'many-to-one'", { derive_vars_transposed( dataset, dataset_merge, - by_vars = exprs(USUBJID), + by_vars = get_admiral_option("subject_keys"), key_var = TESTCD, value_var = VALUE, filter = TESTCD == "T01", @@ -70,42 +70,42 @@ test_that("derive_vars_transposed Test 3: filter merge dataset 'many-to-one'", { ## Test 4: ATC variables are merged properly ---- test_that("derive_vars_transposed Test 4: ATC variables are merged properly", { cm <- tibble::tribble( - ~USUBJID, ~CMGRPID, ~CMREFID, ~CMDECOD, - "BP40257-1001", "14", "1192056", "PARACETAMOL", - "BP40257-1001", "18", "2007001", "SOLUMEDROL", - "BP40257-1002", "19", "2791596", "SPIRONOLACTONE" + ~STUDYID, ~USUBJID, ~CMGRPID, ~CMREFID, ~CMDECOD, + "STUDY01", "BP40257-1001", "14", "1192056", "PARACETAMOL", + "STUDY01", "BP40257-1001", "18", "2007001", "SOLUMEDROL", + "STUDY01", "BP40257-1002", "19", "2791596", "SPIRONOLACTONE" ) facm <- tibble::tribble( - ~USUBJID, ~FAGRPID, ~FAREFID, ~FATESTCD, ~FASTRESC, - "BP40257-1001", "1", "1192056", "CMATC1CD", "N", - "BP40257-1001", "1", "1192056", "CMATC2CD", "N02", - "BP40257-1001", "1", "1192056", "CMATC3CD", "N02B", - "BP40257-1001", "1", "1192056", "CMATC4CD", "N02BE", - "BP40257-1001", "1", "2007001", "CMATC1CD", "D", - "BP40257-1001", "1", "2007001", "CMATC2CD", "D10", - "BP40257-1001", "1", "2007001", "CMATC3CD", "D10A", - "BP40257-1001", "1", "2007001", "CMATC4CD", "D10AA", - "BP40257-1001", "2", "2007001", "CMATC1CD", "D", - "BP40257-1001", "2", "2007001", "CMATC2CD", "D07", - "BP40257-1001", "2", "2007001", "CMATC3CD", "D07A", - "BP40257-1001", "2", "2007001", "CMATC4CD", "D07AA", - "BP40257-1001", "3", "2007001", "CMATC1CD", "H", - "BP40257-1001", "3", "2007001", "CMATC2CD", "H02", - "BP40257-1001", "3", "2007001", "CMATC3CD", "H02A", - "BP40257-1001", "3", "2007001", "CMATC4CD", "H02AB", - "BP40257-1002", "1", "2791596", "CMATC1CD", "C", - "BP40257-1002", "1", "2791596", "CMATC2CD", "C03", - "BP40257-1002", "1", "2791596", "CMATC3CD", "C03D", - "BP40257-1002", "1", "2791596", "CMATC4CD", "C03DA" + ~STUDYID, ~USUBJID, ~FAGRPID, ~FAREFID, ~FATESTCD, ~FASTRESC, + "STUDY01", "BP40257-1001", "1", "1192056", "CMATC1CD", "N", + "STUDY01", "BP40257-1001", "1", "1192056", "CMATC2CD", "N02", + "STUDY01", "BP40257-1001", "1", "1192056", "CMATC3CD", "N02B", + "STUDY01", "BP40257-1001", "1", "1192056", "CMATC4CD", "N02BE", + "STUDY01", "BP40257-1001", "1", "2007001", "CMATC1CD", "D", + "STUDY01", "BP40257-1001", "1", "2007001", "CMATC2CD", "D10", + "STUDY01", "BP40257-1001", "1", "2007001", "CMATC3CD", "D10A", + "STUDY01", "BP40257-1001", "1", "2007001", "CMATC4CD", "D10AA", + "STUDY01", "BP40257-1001", "2", "2007001", "CMATC1CD", "D", + "STUDY01", "BP40257-1001", "2", "2007001", "CMATC2CD", "D07", + "STUDY01", "BP40257-1001", "2", "2007001", "CMATC3CD", "D07A", + "STUDY01", "BP40257-1001", "2", "2007001", "CMATC4CD", "D07AA", + "STUDY01", "BP40257-1001", "3", "2007001", "CMATC1CD", "H", + "STUDY01", "BP40257-1001", "3", "2007001", "CMATC2CD", "H02", + "STUDY01", "BP40257-1001", "3", "2007001", "CMATC3CD", "H02A", + "STUDY01", "BP40257-1001", "3", "2007001", "CMATC4CD", "H02AB", + "STUDY01", "BP40257-1002", "1", "2791596", "CMATC1CD", "C", + "STUDY01", "BP40257-1002", "1", "2791596", "CMATC2CD", "C03", + "STUDY01", "BP40257-1002", "1", "2791596", "CMATC3CD", "C03D", + "STUDY01", "BP40257-1002", "1", "2791596", "CMATC4CD", "C03DA" ) # nolint start expected_output <- tibble::tribble( - ~USUBJID, ~CMGRPID, ~CMREFID, ~CMDECOD, ~ATC1CD, ~ATC2CD, ~ATC3CD, ~ATC4CD, - "BP40257-1001", "14", "1192056", "PARACETAMOL", "N", "N02", "N02B", "N02BE", - "BP40257-1001", "18", "2007001", "SOLUMEDROL", "D", "D07", "D07A", "D07AA", - "BP40257-1001", "18", "2007001", "SOLUMEDROL", "D", "D10", "D10A", "D10AA", - "BP40257-1001", "18", "2007001", "SOLUMEDROL", "H", "H02", "H02A", "H02AB", - "BP40257-1002", "19", "2791596", "SPIRONOLACTONE", "C", "C03", "C03D", "C03DA" + ~STUDYID, ~USUBJID, ~CMGRPID, ~CMREFID, ~CMDECOD, ~ATC1CD, ~ATC2CD, ~ATC3CD, ~ATC4CD, + "STUDY01", "BP40257-1001", "14", "1192056", "PARACETAMOL", "N", "N02", "N02B", "N02BE", + "STUDY01", "BP40257-1001", "18", "2007001", "SOLUMEDROL", "D", "D07", "D07A", "D07AA", + "STUDY01", "BP40257-1001", "18", "2007001", "SOLUMEDROL", "D", "D10", "D10A", "D10AA", + "STUDY01", "BP40257-1001", "18", "2007001", "SOLUMEDROL", "H", "H02", "H02A", "H02AB", + "STUDY01", "BP40257-1002", "19", "2791596", "SPIRONOLACTONE", "C", "C03", "C03D", "C03DA" ) # nolint end actual_output <- derive_vars_atc( @@ -123,42 +123,42 @@ test_that("derive_vars_transposed Test 4: ATC variables are merged properly", { ## Test 5: ATC variables are merged properly ---- test_that("derive_vars_transposed Test 5: ATC variables are merged properly", { cm <- tibble::tribble( - ~USUBJID, ~CMGRPID, ~CMREFID, ~CMDECOD, - "BP40257-1001", "14", "1192056", "PARACETAMOL", - "BP40257-1001", "18", "2007001", "SOLUMEDROL", - "BP40257-1002", "19", "2791596", "SPIRONOLACTONE" + ~STUDYID, ~USUBJID, ~CMGRPID, ~CMREFID, ~CMDECOD, + "STUDY01", "BP40257-1001", "14", "1192056", "PARACETAMOL", + "STUDY01", "BP40257-1001", "18", "2007001", "SOLUMEDROL", + "STUDY01", "BP40257-1002", "19", "2791596", "SPIRONOLACTONE" ) facm <- tibble::tribble( - ~USUBJID, ~FAGRPID, ~FAREFID, ~FATESTCD, ~FASTRESC, - "BP40257-1001", "1", "1192056", "CMATC1CD", "N", - "BP40257-1001", "1", "1192056", "CMATC2CD", "N02", - "BP40257-1001", "1", "1192056", "CMATC3CD", "N02B", - "BP40257-1001", "1", "1192056", "CMATC4CD", "N02BE", - "BP40257-1001", "1", "2007001", "CMATC1CD", "D", - "BP40257-1001", "1", "2007001", "CMATC2CD", "D10", - "BP40257-1001", "1", "2007001", "CMATC3CD", "D10A", - "BP40257-1001", "1", "2007001", "CMATC4CD", "D10AA", - "BP40257-1001", "2", "2007001", "CMATC1CD", "D", - "BP40257-1001", "2", "2007001", "CMATC2CD", "D07", - "BP40257-1001", "2", "2007001", "CMATC3CD", "D07A", - "BP40257-1001", "2", "2007001", "CMATC4CD", "D07AA", - "BP40257-1001", "3", "2007001", "CMATC1CD", "H", - "BP40257-1001", "3", "2007001", "CMATC2CD", "H02", - "BP40257-1001", "3", "2007001", "CMATC3CD", "H02A", - "BP40257-1001", "3", "2007001", "CMATC4CD", "H02AB", - "BP40257-1002", "1", "2791596", "CMATC1CD", "C", - "BP40257-1002", "1", "2791596", "CMATC2CD", "C03", - "BP40257-1002", "1", "2791596", "CMATC3CD", "C03D", - "BP40257-1002", "1", "2791596", "CMATC4CD", "C03DA" + ~STUDYID, ~USUBJID, ~FAGRPID, ~FAREFID, ~FATESTCD, ~FASTRESC, + "STUDY01", "BP40257-1001", "1", "1192056", "CMATC1CD", "N", + "STUDY01", "BP40257-1001", "1", "1192056", "CMATC2CD", "N02", + "STUDY01", "BP40257-1001", "1", "1192056", "CMATC3CD", "N02B", + "STUDY01", "BP40257-1001", "1", "1192056", "CMATC4CD", "N02BE", + "STUDY01", "BP40257-1001", "1", "2007001", "CMATC1CD", "D", + "STUDY01", "BP40257-1001", "1", "2007001", "CMATC2CD", "D10", + "STUDY01", "BP40257-1001", "1", "2007001", "CMATC3CD", "D10A", + "STUDY01", "BP40257-1001", "1", "2007001", "CMATC4CD", "D10AA", + "STUDY01", "BP40257-1001", "2", "2007001", "CMATC1CD", "D", + "STUDY01", "BP40257-1001", "2", "2007001", "CMATC2CD", "D07", + "STUDY01", "BP40257-1001", "2", "2007001", "CMATC3CD", "D07A", + "STUDY01", "BP40257-1001", "2", "2007001", "CMATC4CD", "D07AA", + "STUDY01", "BP40257-1001", "3", "2007001", "CMATC1CD", "H", + "STUDY01", "BP40257-1001", "3", "2007001", "CMATC2CD", "H02", + "STUDY01", "BP40257-1001", "3", "2007001", "CMATC3CD", "H02A", + "STUDY01", "BP40257-1001", "3", "2007001", "CMATC4CD", "H02AB", + "STUDY01", "BP40257-1002", "1", "2791596", "CMATC1CD", "C", + "STUDY01", "BP40257-1002", "1", "2791596", "CMATC2CD", "C03", + "STUDY01", "BP40257-1002", "1", "2791596", "CMATC3CD", "C03D", + "STUDY01", "BP40257-1002", "1", "2791596", "CMATC4CD", "C03DA" ) # nolint start expected_output <- tibble::tribble( - ~USUBJID, ~CMGRPID, ~CMREFID, ~CMDECOD, ~ATC1CD, ~ATC2CD, ~ATC3CD, ~ATC4CD, - "BP40257-1001", "14", "1192056", "PARACETAMOL", "N", "N02", "N02B", "N02BE", - "BP40257-1001", "18", "2007001", "SOLUMEDROL", "D", "D07", "D07A", "D07AA", - "BP40257-1001", "18", "2007001", "SOLUMEDROL", "D", "D10", "D10A", "D10AA", - "BP40257-1001", "18", "2007001", "SOLUMEDROL", "H", "H02", "H02A", "H02AB", - "BP40257-1002", "19", "2791596", "SPIRONOLACTONE", "C", "C03", "C03D", "C03DA" + ~STUDYID, ~USUBJID, ~CMGRPID, ~CMREFID, ~CMDECOD, ~ATC1CD, ~ATC2CD, ~ATC3CD, ~ATC4CD, + "STUDY01", "BP40257-1001", "14", "1192056", "PARACETAMOL", "N", "N02", "N02B", "N02BE", + "STUDY01", "BP40257-1001", "18", "2007001", "SOLUMEDROL", "D", "D07", "D07A", "D07AA", + "STUDY01", "BP40257-1001", "18", "2007001", "SOLUMEDROL", "D", "D10", "D10A", "D10AA", + "STUDY01", "BP40257-1001", "18", "2007001", "SOLUMEDROL", "H", "H02", "H02A", "H02AB", + "STUDY01", "BP40257-1002", "19", "2791596", "SPIRONOLACTONE", "C", "C03", "C03D", "C03DA" ) # nolint end actual_output <- derive_vars_atc( @@ -167,5 +167,6 @@ test_that("derive_vars_transposed Test 5: ATC variables are merged properly", { id_vars = exprs(FAGRPID) ) - expect_dfs_equal(expected_output, actual_output, keys = c("USUBJID", "CMDECOD", "ATC4CD")) + expect_dfs_equal(expected_output, actual_output, keys = c("STUDYID", "USUBJID", + "CMDECOD", "ATC4CD")) }) diff --git a/vignettes/occds.Rmd b/vignettes/occds.Rmd index d08660d169..578c1a6340 100644 --- a/vignettes/occds.Rmd +++ b/vignettes/occds.Rmd @@ -173,33 +173,33 @@ The expected result is the input dataset with ATC variables added. ```{r eval=TRUE} cm <- tibble::tribble( - ~STUDYID, ~USUBJID, ~CMGRPID, ~CMREFID, ~CMDECOD, - "STUDY01", "BP40257-1001", "14", "1192056", "PARACETAMOL", - "STUDY01", "BP40257-1001", "18", "2007001", "SOLUMEDROL", - "STUDY01", "BP40257-1002", "19", "2791596", "SPIRONOLACTONE" + ~STUDYID, ~USUBJID, ~CMGRPID, ~CMREFID, ~CMDECOD, + "STUDY01", "BP40257-1001", "14", "1192056", "PARACETAMOL", + "STUDY01", "BP40257-1001", "18", "2007001", "SOLUMEDROL", + "STUDY01", "BP40257-1002", "19", "2791596", "SPIRONOLACTONE" ) facm <- tibble::tribble( - ~STUDYID, ~USUBJID, ~FAGRPID, ~FAREFID, ~FATESTCD, ~FASTRESC, - "STUDY01", "BP40257-1001", "1", "1192056", "CMATC1CD", "N", - "STUDY01", "BP40257-1001", "1", "1192056", "CMATC2CD", "N02", - "STUDY01", "BP40257-1001", "1", "1192056", "CMATC3CD", "N02B", - "STUDY01", "BP40257-1001", "1", "1192056", "CMATC4CD", "N02BE", - "STUDY01", "BP40257-1001", "1", "2007001", "CMATC1CD", "D", - "STUDY01", "BP40257-1001", "1", "2007001", "CMATC2CD", "D10", - "STUDY01", "BP40257-1001", "1", "2007001", "CMATC3CD", "D10A", - "STUDY01", "BP40257-1001", "1", "2007001", "CMATC4CD", "D10AA", - "STUDY01", "BP40257-1001", "2", "2007001", "CMATC1CD", "D", - "STUDY01", "BP40257-1001", "2", "2007001", "CMATC2CD", "D07", - "STUDY01", "BP40257-1001", "2", "2007001", "CMATC3CD", "D07A", - "STUDY01", "BP40257-1001", "2", "2007001", "CMATC4CD", "D07AA", - "STUDY01", "BP40257-1001", "3", "2007001", "CMATC1CD", "H", - "STUDY01", "BP40257-1001", "3", "2007001", "CMATC2CD", "H02", - "STUDY01", "BP40257-1001", "3", "2007001", "CMATC3CD", "H02A", - "STUDY01", "BP40257-1001", "3", "2007001", "CMATC4CD", "H02AB", - "STUDY01", "BP40257-1002", "1", "2791596", "CMATC1CD", "C", - "STUDY01", "BP40257-1002", "1", "2791596", "CMATC2CD", "C03", - "STUDY01", "BP40257-1002", "1", "2791596", "CMATC3CD", "C03D", - "STUDY01", "BP40257-1002", "1", "2791596", "CMATC4CD", "C03DA" + ~STUDYID, ~USUBJID, ~FAGRPID, ~FAREFID, ~FATESTCD, ~FASTRESC, + "STUDY01", "BP40257-1001", "1", "1192056", "CMATC1CD", "N", + "STUDY01", "BP40257-1001", "1", "1192056", "CMATC2CD", "N02", + "STUDY01", "BP40257-1001", "1", "1192056", "CMATC3CD", "N02B", + "STUDY01", "BP40257-1001", "1", "1192056", "CMATC4CD", "N02BE", + "STUDY01", "BP40257-1001", "1", "2007001", "CMATC1CD", "D", + "STUDY01", "BP40257-1001", "1", "2007001", "CMATC2CD", "D10", + "STUDY01", "BP40257-1001", "1", "2007001", "CMATC3CD", "D10A", + "STUDY01", "BP40257-1001", "1", "2007001", "CMATC4CD", "D10AA", + "STUDY01", "BP40257-1001", "2", "2007001", "CMATC1CD", "D", + "STUDY01", "BP40257-1001", "2", "2007001", "CMATC2CD", "D07", + "STUDY01", "BP40257-1001", "2", "2007001", "CMATC3CD", "D07A", + "STUDY01", "BP40257-1001", "2", "2007001", "CMATC4CD", "D07AA", + "STUDY01", "BP40257-1001", "3", "2007001", "CMATC1CD", "H", + "STUDY01", "BP40257-1001", "3", "2007001", "CMATC2CD", "H02", + "STUDY01", "BP40257-1001", "3", "2007001", "CMATC3CD", "H02A", + "STUDY01", "BP40257-1001", "3", "2007001", "CMATC4CD", "H02AB", + "STUDY01", "BP40257-1002", "1", "2791596", "CMATC1CD", "C", + "STUDY01", "BP40257-1002", "1", "2791596", "CMATC2CD", "C03", + "STUDY01", "BP40257-1002", "1", "2791596", "CMATC3CD", "C03D", + "STUDY01", "BP40257-1002", "1", "2791596", "CMATC4CD", "C03DA" ) derive_vars_atc(cm, facm) From fa7959840c735bace29ba44193a8f333996b72e8 Mon Sep 17 00:00:00 2001 From: ProfessorP Date: Wed, 2 Oct 2024 19:20:22 -0400 Subject: [PATCH 09/13] spellcheck and styler run --- NEWS.md | 4 ++-- .../test-create_single_dose_dataset.R | 6 ++++-- tests/testthat/test-derive_vars_transposed.R | 20 ++++++++++--------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/NEWS.md b/NEWS.md index 8d921d3ab2..d9b6675613 100644 --- a/NEWS.md +++ b/NEWS.md @@ -45,8 +45,8 @@ # admiral 1.1.1 -- `derive_vars_atc()` and `create_single_dose_dataset()` `by_vars` argument updated to use `get_admiral_option("subject_keys")` instead of hardcoded USUBJID or STUDYID. -- test scripts, R, and Rmd files for `create_single_dose_dataset` and `occds.Rmd` updated to include a STUDYID column because of `get_admiral_option("subject_keys")` update above. +- `derive_vars_atc()` and `create_single_dose_dataset()` `by_vars` argument updated to use `get_admiral_option("subject_keys")` instead of USUBJID or STUDYID. +- 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. - `derive_extreme_event()` was fixed such that `check_type = "none"` is accepted again. (#2462) diff --git a/tests/testthat/test-create_single_dose_dataset.R b/tests/testthat/test-create_single_dose_dataset.R index 917db8fdcf..bee80ef413 100644 --- a/tests/testthat/test-create_single_dose_dataset.R +++ b/tests/testthat/test-create_single_dose_dataset.R @@ -136,8 +136,10 @@ test_that("create_single_dose_dataset Test 3: Works for different treatments", { input, start_datetime = ASTDTM, end_datetime = AENDTM, - keep_source_vars = exprs(!!!get_admiral_option("subject_keys"), - EXDOSFRQ, ASTDT, ASTDTM, AENDT, AENDTM, EXTRT) + keep_source_vars = exprs( + !!!get_admiral_option("subject_keys"), + EXDOSFRQ, ASTDT, ASTDTM, AENDT, AENDTM, EXTRT + ) ), expected_output, keys = c("EXTRT", "ASTDT") diff --git a/tests/testthat/test-derive_vars_transposed.R b/tests/testthat/test-derive_vars_transposed.R index 6472afba9f..b6377489fe 100644 --- a/tests/testthat/test-derive_vars_transposed.R +++ b/tests/testthat/test-derive_vars_transposed.R @@ -1,15 +1,15 @@ dataset <- tibble::tribble( ~STUDYID, ~USUBJID, ~VAR1, - "STUDY01", "P01", 3, - "STUDY01", "P02", 31, - "STUDY01", "P03", 42 + "STUDY01", "P01", 3, + "STUDY01", "P02", 31, + "STUDY01", "P03", 42 ) dataset_merge <- tibble::tribble( ~STUDYID, ~USUBJID, ~TESTCD, ~VALUE, - "STUDY01", "P01", "T01", 31, - "STUDY01", "P01", "T02", 5, - "STUDY01", "P02", "T01", 3, - "STUDY01", "P03", "T02", 9 + "STUDY01", "P01", "T01", 31, + "STUDY01", "P01", "T02", 5, + "STUDY01", "P02", "T01", 3, + "STUDY01", "P03", "T02", 9 ) ## Test 1: the merge dataset is transposed and merged correctly ---- @@ -167,6 +167,8 @@ test_that("derive_vars_transposed Test 5: ATC variables are merged properly", { id_vars = exprs(FAGRPID) ) - expect_dfs_equal(expected_output, actual_output, keys = c("STUDYID", "USUBJID", - "CMDECOD", "ATC4CD")) + expect_dfs_equal(expected_output, actual_output, keys = c( + "STUDYID", "USUBJID", + "CMDECOD", "ATC4CD" + )) }) From 9369763777251eb8d0485da098a5bd10d0d26e81 Mon Sep 17 00:00:00 2001 From: ProfessorP Date: Wed, 2 Oct 2024 19:23:13 -0400 Subject: [PATCH 10/13] spellcheck fix again --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index d9b6675613..50cb0d0b71 100644 --- a/NEWS.md +++ b/NEWS.md @@ -45,7 +45,7 @@ # admiral 1.1.1 -- `derive_vars_atc()` and `create_single_dose_dataset()` `by_vars` argument updated to use `get_admiral_option("subject_keys")` instead of USUBJID or STUDYID. +- `derive_vars_atc()` and `create_single_dose_dataset()` `by_vars` argument updated to use `get_admiral_option("subject_keys")` instead of `USUBJID` or `STUDYID`. - 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. - `derive_extreme_event()` was fixed such that `check_type = "none"` is accepted again. (#2462) From 9694ee55f4c4bf66d40cc6d2df24ff4e8928598f Mon Sep 17 00:00:00 2001 From: ProfessorP Date: Thu, 3 Oct 2024 11:04:07 -0400 Subject: [PATCH 11/13] moved updates under admiral development version in News.md --- NEWS.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/NEWS.md b/NEWS.md index 50cb0d0b71..8313f5c250 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,6 +10,10 @@ - Replace use of `data("sdtm")` with `sdtm <- pharmaverse::sdtm` in templates and vignettes. (#2498) ## Updates of Existing Functions +- `derive_vars_atc()` and `create_single_dose_dataset()` `by_vars` argument updated to use `get_admiral_option("subject_keys")` instead of `USUBJID` or `STUDYID`. +- 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. +- `derive_extreme_event()` was fixed such that `check_type = "none"` is accepted +again. (#2462) ## Breaking Changes @@ -45,11 +49,6 @@ # admiral 1.1.1 -- `derive_vars_atc()` and `create_single_dose_dataset()` `by_vars` argument updated to use `get_admiral_option("subject_keys")` instead of `USUBJID` or `STUDYID`. -- 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. -- `derive_extreme_event()` was fixed such that `check_type = "none"` is accepted -again. (#2462) - - `derive_locf_records()` documentation example was fixed to display LOCF records. (#2461) # admiral 1.1.0 From c389dd9b4ffd76088a461245697a0e7109caf804 Mon Sep 17 00:00:00 2001 From: ProfessorP Date: Wed, 30 Oct 2024 01:10:20 -0400 Subject: [PATCH 12/13] Aligned tables and changed the STUDYID, USUBJID to get_admiral_option("subject_keys") for the bds_exposure vignette --- NEWS.md | 10 ++++--- .../test-create_single_dose_dataset.R | 30 +++++++++---------- vignettes/bds_exposure.Rmd | 6 ++-- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/NEWS.md b/NEWS.md index 8313f5c250..6b771a130b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,10 +10,8 @@ - Replace use of `data("sdtm")` with `sdtm <- pharmaverse::sdtm` in templates and vignettes. (#2498) ## Updates of Existing Functions -- `derive_vars_atc()` and `create_single_dose_dataset()` `by_vars` argument updated to use `get_admiral_option("subject_keys")` instead of `USUBJID` or `STUDYID`. -- 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. -- `derive_extreme_event()` was fixed such that `check_type = "none"` is accepted -again. (#2462) + + ## Breaking Changes @@ -50,6 +48,8 @@ again. (#2462) # admiral 1.1.1 - `derive_locf_records()` documentation example was fixed to display LOCF records. (#2461) +- `derive_vars_atc()` and `create_single_dose_dataset()` `by_vars` argument updated to use `get_admiral_option("subject_keys")` instead of `USUBJID` or `STUDYID` in `bds_exposure.Rmd`. +- 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. # admiral 1.1.0 @@ -61,6 +61,8 @@ again. (#2462) - New `country_code_lookup()` metadata added to decode countries based on [ISO 3166 codes](https://www.iso.org/iso-3166-country-codes.html). (#2388) ## Updates of Existing Functions +- `derive_extreme_event()` was fixed such that `check_type = "none"` is accepted +again. (#2462) - `group_var` (optional) parameter is added to `derive_var_trtemfl()` to derive `TRTEMFL` for AE data if the data are collected as one episode of AE with multiple lines. (#2302) diff --git a/tests/testthat/test-create_single_dose_dataset.R b/tests/testthat/test-create_single_dose_dataset.R index bee80ef413..bf84ffde09 100644 --- a/tests/testthat/test-create_single_dose_dataset.R +++ b/tests/testthat/test-create_single_dose_dataset.R @@ -2,24 +2,24 @@ ## Test 1: Works as expected for Q*/EVERY * cases ---- test_that("create_single_dose_dataset Test 1: Works as expected for Q*/EVERY * cases", { input <- tibble::tribble( - ~STUDYID, ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~AENDT, - "STUDY01", "P01", "Q2D", ymd("2021-01-01"), ymd("2021-01-07"), - "STUDY01", "P01", "Q3D", ymd("2021-01-08"), ymd("2021-01-14"), + ~STUDYID, ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~AENDT, + "STUDY01", "P01", "Q2D", ymd("2021-01-01"), ymd("2021-01-07"), + "STUDY01", "P01", "Q3D", ymd("2021-01-08"), ymd("2021-01-14"), "STUDY01", "P01", "EVERY 2 WEEKS", ymd("2021-01-15"), ymd("2021-01-29"), - "STUDY01", "P02", "ONCE", ymd("2021-02-02"), ymd("2021-02-02") + "STUDY01", "P02", "ONCE", ymd("2021-02-02"), ymd("2021-02-02") ) expected_output <- tibble::tribble( - ~STUDYID, ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~AENDT, - "STUDY01", "P01", "ONCE", ymd("2021-01-01"), ymd("2021-01-01"), - "STUDY01", "P01", "ONCE", ymd("2021-01-03"), ymd("2021-01-03"), - "STUDY01", "P01", "ONCE", ymd("2021-01-05"), ymd("2021-01-05"), - "STUDY01", "P01", "ONCE", ymd("2021-01-07"), ymd("2021-01-07"), - "STUDY01", "P01", "ONCE", ymd("2021-01-08"), ymd("2021-01-08"), - "STUDY01", "P01", "ONCE", ymd("2021-01-11"), ymd("2021-01-11"), - "STUDY01", "P01", "ONCE", ymd("2021-01-14"), ymd("2021-01-14"), - "STUDY01", "P01", "ONCE", ymd("2021-01-15"), ymd("2021-01-15"), - "STUDY01", "P01", "ONCE", ymd("2021-01-29"), ymd("2021-01-29"), - "STUDY01", "P02", "ONCE", ymd("2021-02-02"), ymd("2021-02-02") + ~STUDYID, ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~AENDT, + "STUDY01", "P01", "ONCE", ymd("2021-01-01"), ymd("2021-01-01"), + "STUDY01", "P01", "ONCE", ymd("2021-01-03"), ymd("2021-01-03"), + "STUDY01", "P01", "ONCE", ymd("2021-01-05"), ymd("2021-01-05"), + "STUDY01", "P01", "ONCE", ymd("2021-01-07"), ymd("2021-01-07"), + "STUDY01", "P01", "ONCE", ymd("2021-01-08"), ymd("2021-01-08"), + "STUDY01", "P01", "ONCE", ymd("2021-01-11"), ymd("2021-01-11"), + "STUDY01", "P01", "ONCE", ymd("2021-01-14"), ymd("2021-01-14"), + "STUDY01", "P01", "ONCE", ymd("2021-01-15"), ymd("2021-01-15"), + "STUDY01", "P01", "ONCE", ymd("2021-01-29"), ymd("2021-01-29"), + "STUDY01", "P02", "ONCE", ymd("2021-02-02"), ymd("2021-02-02") ) expect_dfs_equal( diff --git a/vignettes/bds_exposure.Rmd b/vignettes/bds_exposure.Rmd index bbb86e5993..212d9002b7 100644 --- a/vignettes/bds_exposure.Rmd +++ b/vignettes/bds_exposure.Rmd @@ -81,7 +81,7 @@ adex <- derive_vars_merged( ex, dataset_add = adsl, new_vars = adsl_vars, - by_vars = exprs(STUDYID, USUBJID) + by_vars = get_admiral_option("subject_keys") ) ``` @@ -581,7 +581,7 @@ example call is: adex <- derive_var_obs_number( adex, new_var = ASEQ, - by_vars = exprs(STUDYID, USUBJID), + by_vars = get_admiral_option("subject_keys"), order = exprs(PARCAT1, ASTDT, VISIT, VISITNUM, EXSEQ, PARAMN), check_type = "error" ) @@ -602,7 +602,7 @@ If needed, the other `ADSL` variables can now be added: adex <- adex %>% derive_vars_merged( dataset_add = select(adsl, !!!negate_vars(adsl_vars)), - by_vars = exprs(STUDYID, USUBJID) + by_vars = get_admiral_option("subject_keys") ) ``` ## Add Labels and Attributes {#attributes} From ee9a029a0ec839000ed469833df436da338b902d Mon Sep 17 00:00:00 2001 From: ProfessorP Date: Wed, 30 Oct 2024 01:16:03 -0400 Subject: [PATCH 13/13] ran styler on requested files from last push --- .../test-create_single_dose_dataset.R | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/testthat/test-create_single_dose_dataset.R b/tests/testthat/test-create_single_dose_dataset.R index bf84ffde09..bee80ef413 100644 --- a/tests/testthat/test-create_single_dose_dataset.R +++ b/tests/testthat/test-create_single_dose_dataset.R @@ -2,24 +2,24 @@ ## Test 1: Works as expected for Q*/EVERY * cases ---- test_that("create_single_dose_dataset Test 1: Works as expected for Q*/EVERY * cases", { input <- tibble::tribble( - ~STUDYID, ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~AENDT, - "STUDY01", "P01", "Q2D", ymd("2021-01-01"), ymd("2021-01-07"), - "STUDY01", "P01", "Q3D", ymd("2021-01-08"), ymd("2021-01-14"), + ~STUDYID, ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~AENDT, + "STUDY01", "P01", "Q2D", ymd("2021-01-01"), ymd("2021-01-07"), + "STUDY01", "P01", "Q3D", ymd("2021-01-08"), ymd("2021-01-14"), "STUDY01", "P01", "EVERY 2 WEEKS", ymd("2021-01-15"), ymd("2021-01-29"), - "STUDY01", "P02", "ONCE", ymd("2021-02-02"), ymd("2021-02-02") + "STUDY01", "P02", "ONCE", ymd("2021-02-02"), ymd("2021-02-02") ) expected_output <- tibble::tribble( - ~STUDYID, ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~AENDT, - "STUDY01", "P01", "ONCE", ymd("2021-01-01"), ymd("2021-01-01"), - "STUDY01", "P01", "ONCE", ymd("2021-01-03"), ymd("2021-01-03"), - "STUDY01", "P01", "ONCE", ymd("2021-01-05"), ymd("2021-01-05"), - "STUDY01", "P01", "ONCE", ymd("2021-01-07"), ymd("2021-01-07"), - "STUDY01", "P01", "ONCE", ymd("2021-01-08"), ymd("2021-01-08"), - "STUDY01", "P01", "ONCE", ymd("2021-01-11"), ymd("2021-01-11"), - "STUDY01", "P01", "ONCE", ymd("2021-01-14"), ymd("2021-01-14"), - "STUDY01", "P01", "ONCE", ymd("2021-01-15"), ymd("2021-01-15"), - "STUDY01", "P01", "ONCE", ymd("2021-01-29"), ymd("2021-01-29"), - "STUDY01", "P02", "ONCE", ymd("2021-02-02"), ymd("2021-02-02") + ~STUDYID, ~USUBJID, ~EXDOSFRQ, ~ASTDT, ~AENDT, + "STUDY01", "P01", "ONCE", ymd("2021-01-01"), ymd("2021-01-01"), + "STUDY01", "P01", "ONCE", ymd("2021-01-03"), ymd("2021-01-03"), + "STUDY01", "P01", "ONCE", ymd("2021-01-05"), ymd("2021-01-05"), + "STUDY01", "P01", "ONCE", ymd("2021-01-07"), ymd("2021-01-07"), + "STUDY01", "P01", "ONCE", ymd("2021-01-08"), ymd("2021-01-08"), + "STUDY01", "P01", "ONCE", ymd("2021-01-11"), ymd("2021-01-11"), + "STUDY01", "P01", "ONCE", ymd("2021-01-14"), ymd("2021-01-14"), + "STUDY01", "P01", "ONCE", ymd("2021-01-15"), ymd("2021-01-15"), + "STUDY01", "P01", "ONCE", ymd("2021-01-29"), ymd("2021-01-29"), + "STUDY01", "P02", "ONCE", ymd("2021-02-02"), ymd("2021-02-02") ) expect_dfs_equal(