Skip to content

Commit

Permalink
Merge 544d37c into f4bbde7
Browse files Browse the repository at this point in the history
  • Loading branch information
BFalquet committed Sep 12, 2024
2 parents f4bbde7 + 544d37c commit 075441f
Show file tree
Hide file tree
Showing 10 changed files with 300 additions and 1 deletion.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Collate:
'ael01_nollt.R'
'ael02.R'
'ael03.R'
'ael04.R'
'aet01.R'
'aet01_aesi.R'
'aet02.R'
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export(ael02_pre)
export(ael03)
export(ael03_main)
export(ael03_pre)
export(ael04)
export(ael04_main)
export(ael04_pre)
export(aet01)
export(aet01_aesi)
export(aet01_aesi_main)
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# chevron 0.2.6.9020

* Add `AEL02`, `AEL03`, `CML02A_gl` templates.
* Add `AEL02`, `AEL03`, `AEL04`, `CML02A_gl` templates.
* Modify the post processing of `MHT01` to allow multiple `row_split_var`.
* Improve the `report_null` method to facilitate the creation of null reports
* Export the `std_postprocessing` function to simplify post processing logic.
Expand Down
64 changes: 64 additions & 0 deletions R/ael04.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# ael04_main ----

#' @describeIn ael04 Main TLG function
#'
#' @inheritParams gen_args
#' @returns the main function returns an `rlistings` or a `list` object.
#' @export
#'
ael04_main <- modify_default_args(
std_listing,
dataset = "adsl",
key_cols = "ID",
disp_cols = c("ASR", "TRTSDTM", "EOSDY", "DTHADY", "DTHCAUS", "ADTHAUT"),
split_into_pages_by_var = "ACTARM"
)


#' @describeIn ael04 Preprocessing
#'
#' @inheritParams ael04_main
#' @inheritParams gen_args
#'
#' @export
#'
ael04_pre <- function(adam_db,
dataset = "adsl",
split_into_pages_by_var = "ACTARM",
...) {
adam_db[[dataset]] <- adam_db[[dataset]] %>%
filter(!is.na(.data$DTHADY)) %>%
mutate(
across(
all_of(c(split_into_pages_by_var, "DTHCAUS", "ADTHAUT")),
~ reformat(.x, missing_rule)
)
) %>%
mutate(
ID = create_id_listings(.data$SITEID, .data$SUBJID),
ASR = with_label(paste(.data$AGE, .data$SEX, .data$RACE, sep = "/"), "Age/Sex/Race"),
TRTSDTM = with_label(
.data$TRTSDTM,
"Date of\nFirst Study\nDrug\nAdministration"
),
!!split_into_pages_by_var := with_label(.data[[split_into_pages_by_var]], "Treatment"),
EOSDY = with_label(.data$EOSDY, "Day of Last\nStudy Drug\nAdministration"),
DTHADY = with_label(.data$DTHADY, "Day of\nDeath"),
DTHCAUS = with_label(.data$DTHCAUS, "Cause of Death"),
ADTHAUT = with_label(.data$ADTHAUT, "Autopsy\nPerformed?")
)

adam_db
}

#' `AEL04` Listing 1 (Default) Listing of Patient Deaths.
#'
#' @include chevron_tlg-S4class.R
#' @export
#'
#' @examples
#' res <- run(ael04, syn_data)
ael04 <- chevron_l(
main = ael04_main,
preprocess = ael04_pre
)
1 change: 1 addition & 0 deletions _pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ reference:
- ael01_nollt
- ael02
- ael03
- ael04
- aet01
- aet01_aesi
- aet02
Expand Down
4 changes: 4 additions & 0 deletions data-raw/syn_data_creation.R
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ syn_test_data <- function() {
sd$adsl$ETHNIC <- factor(trimws(sd$adsl$ETHNIC), levels = trimws(levels(sd$adsl$ETHNIC)))
attr(sd$adsl$ETHNIC, "label") <- "Ethnicity"

# useful for ael04
sd$adsl$TRTSDTM <- lubridate::force_tz(sd$adsl$TRTSDTM, tzone = "UTC")


adsub <- sd$adsub
adsub_wide_ls <- dunlin::poly_pivot_wider(
adsub,
Expand Down
Binary file modified data/syn_data.rda
Binary file not shown.
56 changes: 56 additions & 0 deletions man/ael04.Rd

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

143 changes: 143 additions & 0 deletions tests/testthat/_snaps/ael04.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# ael04 works with adsl dataset

Code
cat(export_as_txt(res, lpp = 100, cpp = 110))
Output
ACTARM: C: Combination
——————————————————————————————————————————————————————————————————————————————————————————————————
Date of
First Study Day of Last
Drug Study Drug Day of
Center/Patients ID Age/Sex/Race Administration Administration Death Cause of Death
——————————————————————————————————————————————————————————————————————————————————————————————————
BRA-11/9 40/M/ASIAN 25MAR2019 1056 1091 DISEASE PROGRESSION
CHN-15/201 49/M/ASIAN 05MAR2019 1082 1084 ADVERSE EVENT
CHN-15/245 34/F/WHITE 29MAR2019 1057 1056 DISEASE PROGRESSION
\s\nACTARM: C: Combination
———————————————————————————————
Autopsy
Center/Patients ID Performed?
———————————————————————————————
BRA-11/9 Yes
CHN-15/201 Yes
CHN-15/245 Yes
\s\nACTARM: B: Placebo
—————————————————————————————————————————————————————————————————————————————————————————————————————————————
Date of
First Study Day of Last
Drug Study Drug Day of Autopsy
Center/Patients ID Age/Sex/Race Administration Administration Death Cause of Death Performed?
—————————————————————————————————————————————————————————————————————————————————————————————————————————————
CAN-1/341 43/F/ASIAN 23MAY2019 998 1013 SUICIDE Yes
CHN-1/307 24/M/ASIAN 11MAR2019 1076 1121 LOST TO FOLLOW UP <Missing>
CHN-13/240 42/M/ASIAN 08APR2019 1044 1086 ADVERSE EVENT Yes
CHN-7/126 27/M/WHITE 02MAY2019 1025 1066 ADVERSE EVENT Yes
\s\nACTARM: A: Drug X
——————————————————————————————————————————————————————————————————————————————————————————————————
Date of
First Study Day of Last
Drug Study Drug Day of
Center/Patients ID Age/Sex/Race Administration Administration Death Cause of Death
——————————————————————————————————————————————————————————————————————————————————————————————————
CHN-3/128 32/M/ASIAN 24FEB2019 1084 1105 ADVERSE EVENT
RUS-1/52 40/F/ASIAN 18MAR2019 1064 1069 DISEASE PROGRESSION
\s\nACTARM: A: Drug X
———————————————————————————————
Autopsy
Center/Patients ID Performed?
———————————————————————————————
CHN-3/128 Yes
RUS-1/52 Yes

# ael04 can handle all missing values

Code
cat(export_as_txt(res, lpp = 100, cpp = 110))
Output
ACTARM: <Missing>
——————————————————————————————————————————————————————————————————————————————————————————————————————————
Date of
First Study Day of Last
Drug Study Drug Day of Autopsy
Center/Patients ID Age/Sex/Race Administration Administration Death Cause of Death Performed?
——————————————————————————————————————————————————————————————————————————————————————————————————————————
BRA-11/9 40/M/ASIAN 25MAR2019 1056 1091 <Missing> Yes
CAN-1/341 43/F/ASIAN 23MAY2019 998 1013 <Missing> Yes
CHN-1/307 24/M/ASIAN 11MAR2019 1076 1121 <Missing> <Missing>
CHN-13/240 42/M/ASIAN 08APR2019 1044 1086 <Missing> Yes
CHN-15/201 49/M/ASIAN 05MAR2019 1082 1084 <Missing> Yes
CHN-15/245 34/F/WHITE 29MAR2019 1057 1056 <Missing> Yes
CHN-3/128 32/M/ASIAN 24FEB2019 1084 1105 <Missing> Yes
CHN-7/126 27/M/WHITE 02MAY2019 1025 1066 <Missing> Yes
RUS-1/52 40/F/ASIAN 18MAR2019 1064 1069 <Missing> Yes

# ael04 functions work as expected

Code
cat(export_as_txt(res, lpp = 100, cpp = 110))
Output
ACTARM: C: Combination
——————————————————————————————————————————————————————————————————————————————————————————————————
Date of
First Study Day of Last
Drug Study Drug Day of
Center/Patients ID Age/Sex/Race Administration Administration Death Cause of Death
——————————————————————————————————————————————————————————————————————————————————————————————————
BRA-11/9 40/M/ASIAN 25MAR2019 1056 1091 DISEASE PROGRESSION
CHN-15/201 49/M/ASIAN 05MAR2019 1082 1084 ADVERSE EVENT
CHN-15/245 34/F/WHITE 29MAR2019 1057 1056 DISEASE PROGRESSION
\s\nACTARM: C: Combination
———————————————————————————————
Autopsy
Center/Patients ID Performed?
———————————————————————————————
BRA-11/9 Yes
CHN-15/201 Yes
CHN-15/245 Yes
\s\nACTARM: B: Placebo
—————————————————————————————————————————————————————————————————————————————————————————————————————————————
Date of
First Study Day of Last
Drug Study Drug Day of Autopsy
Center/Patients ID Age/Sex/Race Administration Administration Death Cause of Death Performed?
—————————————————————————————————————————————————————————————————————————————————————————————————————————————
CAN-1/341 43/F/ASIAN 23MAY2019 998 1013 SUICIDE Yes
CHN-1/307 24/M/ASIAN 11MAR2019 1076 1121 LOST TO FOLLOW UP <Missing>
CHN-13/240 42/M/ASIAN 08APR2019 1044 1086 ADVERSE EVENT Yes
CHN-7/126 27/M/WHITE 02MAY2019 1025 1066 ADVERSE EVENT Yes
\s\nACTARM: A: Drug X
——————————————————————————————————————————————————————————————————————————————————————————————————
Date of
First Study Day of Last
Drug Study Drug Day of
Center/Patients ID Age/Sex/Race Administration Administration Death Cause of Death
——————————————————————————————————————————————————————————————————————————————————————————————————
CHN-3/128 32/M/ASIAN 24FEB2019 1084 1105 ADVERSE EVENT
RUS-1/52 40/F/ASIAN 18MAR2019 1064 1069 DISEASE PROGRESSION
\s\nACTARM: A: Drug X
———————————————————————————————
Autopsy
Center/Patients ID Performed?
———————————————————————————————
CHN-3/128 Yes
RUS-1/52 Yes

27 changes: 27 additions & 0 deletions tests/testthat/test-ael04.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# ael04 ----

test_that("ael04 works with adsl dataset", {
expect_silent(
res <- run(ael04, syn_data, dataset = "adsl")
)
expect_snapshot(cat(export_as_txt(res, lpp = 100, cpp = 110)))
})

test_that("ael04 can handle all missing values", {
proc_data <- syn_data
proc_data$adsl <- proc_data$adsl %>%
mutate(
ACTARM = NA_character_,
DTHCAUS = NA_character_
)

expect_silent(res <- run(ael04, proc_data))
expect_snapshot(cat(export_as_txt(res, lpp = 100, cpp = 110)))
})

# ael04 functions ----

test_that("ael04 functions work as expected", {
expect_silent(res <- ael04_pre(syn_data) %>% ael04_main())
expect_snapshot(cat(export_as_txt(res, lpp = 100, cpp = 110)))
})

0 comments on commit 075441f

Please sign in to comment.