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

add prototype #754

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,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.9006

* Add `AEL02`, `AEL03` templates.
* Add `AEL02`, `AEL03`, `AEL04` templates.
* Modify the post processing of `MHT01` to allow multiple `row_split_var`.

# chevron 0.2.6
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",
arm_var = "ACTARM",
BFalquet marked this conversation as resolved.
Show resolved Hide resolved
...) {
adam_db[[dataset]] <- adam_db[[dataset]] %>%
filter(!is.na(.data$DTHADY)) %>%
mutate(
across(
all_of(c(arm_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"
),
!!arm_var := with_label(.data[[arm_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 @@ -53,6 +53,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 @@ -150,6 +150,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.
58 changes: 58 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 26MAR2019 1056 1091 DISEASE PROGRESSION
CHN-15/201 49/M/ASIAN 05MAR2019 1082 1085 ADVERSE EVENT
CHN-15/245 34/F/WHITE 29MAR2019 1057 1057 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 1014 SUICIDE Yes
CHN-1/307 24/M/ASIAN 11MAR2019 1076 1122 LOST TO FOLLOW UP <Missing>
CHN-13/240 42/M/ASIAN 08APR2019 1044 1087 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 1106 ADVERSE EVENT
RUS-1/52 40/F/ASIAN 18MAR2019 1064 1070 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 26MAR2019 1056 1091 <Missing> Yes
CAN-1/341 43/F/ASIAN 23MAY2019 998 1014 <Missing> Yes
CHN-1/307 24/M/ASIAN 11MAR2019 1076 1122 <Missing> <Missing>
CHN-13/240 42/M/ASIAN 08APR2019 1044 1087 <Missing> Yes
CHN-15/201 49/M/ASIAN 05MAR2019 1082 1085 <Missing> Yes
CHN-15/245 34/F/WHITE 29MAR2019 1057 1057 <Missing> Yes
CHN-3/128 32/M/ASIAN 24FEB2019 1084 1106 <Missing> Yes
CHN-7/126 27/M/WHITE 02MAY2019 1025 1066 <Missing> Yes
RUS-1/52 40/F/ASIAN 18MAR2019 1064 1070 <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 26MAR2019 1056 1091 DISEASE PROGRESSION
CHN-15/201 49/M/ASIAN 05MAR2019 1082 1085 ADVERSE EVENT
CHN-15/245 34/F/WHITE 29MAR2019 1057 1057 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 1014 SUICIDE Yes
CHN-1/307 24/M/ASIAN 11MAR2019 1076 1122 LOST TO FOLLOW UP <Missing>
CHN-13/240 42/M/ASIAN 08APR2019 1044 1087 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 1106 ADVERSE EVENT
RUS-1/52 40/F/ASIAN 18MAR2019 1064 1070 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)))
})
Loading