Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Closes #2501-general-issue-make-subject-keys-flexible-in-all-functions #2516

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
</details>

# 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`.
ProfessorP-beep marked this conversation as resolved.
Show resolved Hide resolved
- 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)

Expand Down
27 changes: 14 additions & 13 deletions R/create_single_dose_dataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
#' )
#'
Expand All @@ -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")
#' )
#'
Expand All @@ -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")
#' )
#'
Expand Down Expand Up @@ -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)) %>%
Expand Down Expand Up @@ -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))
Expand Down
55 changes: 29 additions & 26 deletions R/derive_vars_transposed.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
ProfessorP-beep marked this conversation as resolved.
Show resolved Hide resolved
#' )
#' 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"
ProfessorP-beep marked this conversation as resolved.
Show resolved Hide resolved
#' )
#'
#' 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))
Expand Down
28 changes: 14 additions & 14 deletions man/create_single_dose_dataset.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 26 additions & 26 deletions man/derive_vars_atc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion tests/testthat/_snaps/create_single_dose_dataset.md
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand Down
17 changes: 9 additions & 8 deletions tests/testthat/_snaps/derive_vars_transposed.md
Original file line number Diff line number Diff line change
@@ -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
<chr> <dbl> <dbl>
1 P01 3 31
2 P02 31 3
3 P03 42 NA
# A tibble: 3 x 4
STUDYID USUBJID VAR1 T01
<chr> <chr> <dbl> <dbl>
1 STUDY01 P01 3 31
2 STUDY01 P02 31 3
3 STUDY01 P03 42 NA

Loading
Loading