diff --git a/NEWS.md b/NEWS.md index 7bb95dc68..6b771a130 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,6 +11,8 @@ ## Updates of Existing Functions + + ## Breaking Changes - The following function arguments are entering the next phase of the deprecation process: (#2487) @@ -45,11 +47,9 @@ # admiral 1.1.1 - -- `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) +- `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/R/create_single_dose_dataset.R b/R/create_single_dose_dataset.R index b492b9bb5..1570a3e01 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") #' ) #' @@ -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)) %>% @@ -450,7 +450,8 @@ 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 dc560401e..3b167d9e9 100644 --- a/R/derive_vars_transposed.R +++ b/R/derive_vars_transposed.R @@ -226,39 +226,42 @@ 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) derive_vars_atc <- function(dataset, dataset_facm, - by_vars = exprs(USUBJID, CMREFID = FAREFID), + by_vars = exprs( + !!!get_admiral_option("subject_keys"), + CMREFID = FAREFID + ), id_vars = NULL, value_var = FASTRESC) { value_var <- assert_symbol(enexpr(value_var)) diff --git a/man/create_single_dose_dataset.Rd b/man/create_single_dose_dataset.Rd index a89b34fd8..b99552c1d 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{ @@ -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") ) @@ -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)) \%>\% diff --git a/man/derive_vars_atc.Rd b/man/derive_vars_atc.Rd index 336cad224..729b237f9 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), id_vars = NULL, value_var = FASTRESC ) @@ -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 a5fa5b850..6484d124f 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 13b2f7381..d26b5ad58 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 e8898fa4c..bee80ef41 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,10 @@ 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 +155,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 +194,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 +210,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 +226,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 +239,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 +250,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 +269,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 +283,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 +328,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 +339,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 +389,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 +407,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 b25ab9fd1..b6377489f 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,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("USUBJID", "CMDECOD", "ATC4CD")) + expect_dfs_equal(expected_output, actual_output, keys = c( + "STUDYID", "USUBJID", + "CMDECOD", "ATC4CD" + )) }) diff --git a/vignettes/bds_exposure.Rmd b/vignettes/bds_exposure.Rmd index 673f08e76..212d9002b 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") ) ``` @@ -361,7 +361,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(get_admiral_option("subject_keys"), adsl_vars), input_code = "DOSE", set_values_to = exprs( PARAMCD = "TDOSE", @@ -441,7 +441,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) @@ -465,7 +465,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" @@ -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} diff --git a/vignettes/occds.Rmd b/vignettes/occds.Rmd index f481bae96..578c1a634 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)