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

cml02a_gl listing #753

Merged
merged 11 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -92,6 +92,7 @@ Collate:
'cfbt01.R'
'checks.R'
'chevron_tlg-S4methods.R'
'cml02a_gl.R'
'cmt01a.R'
'cmt02_pt.R'
'coxt01.R'
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ export(chevron_g)
export(chevron_l)
export(chevron_simple)
export(chevron_t)
export(cml02a_gl)
export(cml02a_gl_main)
export(cml02a_gl_pre)
export(cmt01_label)
export(cmt01a)
export(cmt01a_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.9019

* Add `AEL02`, `AEL03` templates.
* Add `AEL02`, `AEL03`, `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
3 changes: 2 additions & 1 deletion R/ael01_nollt.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ ael01_nollt_main <- modify_default_args(
dataset = "adae",
key_cols = c("AEBODSYS", "AEDECOD"),
disp_cols = "AETERM",
split_into_pages_by_var = NULL
split_into_pages_by_var = NULL,
unique_rows = TRUE
)

#' @describeIn ael01_nollt Preprocessing
Expand Down
51 changes: 51 additions & 0 deletions R/cml02a_gl.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# cml02a_gl_main ----

#' @describeIn cml02a_gl Main TLG function
#'
#' @inheritParams gen_args
#' @returns the main function returns an `rlistings` or a `list` object.
#' @export
#'
cml02a_gl_main <- modify_default_args(std_listing,
BFalquet marked this conversation as resolved.
Show resolved Hide resolved
dataset = "adcm",
key_cols = c("ATC2", "CMDECOD"),
disp_cols = c("ATC2", "CMDECOD", "CMTRT"),
split_into_pages_by_var = NULL,
unique_rows = TRUE
)

#' @describeIn cml02a_gl Preprocessing
#'
#' @inheritParams cml02a_gl_main
#' @inheritParams gen_args
#' @returns the preprocessing function returns a `list` of `data.frame`.
#'
#' @export
#'
cml02a_gl_pre <- function(adam_db,
BFalquet marked this conversation as resolved.
Show resolved Hide resolved
dataset = "adcm",
disp_cols = c("ATC2", "CMDECOD", "CMTRT"),
...) {
adam_db[[dataset]] <- adam_db[[dataset]] %>%
mutate(across(all_of(disp_cols), ~ reformat(.x, nocoding))) %>%
mutate(
ATC2 = with_label(.data$ATC2, "ATC Class Level 2"),
CMDECOD = with_label(.data$CMDECOD, "WHODrug Preferred Name"),
CMTRT = with_label(.data$CMTRT, "Investigator-Specified Treatment Term")
)

adam_db
}

#' `CML02A_GL` Listing 1 (Default) Concomitant Medication Class Level 2, Preferred Name, and Investigator-Specified
#' Terms.
#'
#' @include chevron_tlg-S4class.R
#' @export
#'
#' @examples
#' run(cml02a_gl, syn_data)
cml02a_gl <- chevron_l(
main = cml02a_gl_main,
preprocess = cml02a_gl_pre
)
3 changes: 2 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ std_listing <- function(adam_db,
key_cols,
disp_cols,
split_into_pages_by_var,
unique_rows = FALSE,
...) {
assert_all_tablenames(adam_db, dataset)
assert_valid_variable(adam_db[[dataset]], c(key_cols, disp_cols), label = paste0("adam_db$", dataset))
Expand All @@ -58,7 +59,7 @@ std_listing <- function(adam_db,
split_into_pages_by_var = split_into_pages_by_var,
...,
default_formatting = listing_format_chevron(),
unique_rows = TRUE
unique_rows = unique_rows
)
}

Expand Down
1 change: 1 addition & 0 deletions _pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ reference:
- aet05_all
- aet10
- cfbt01
- cml02a_gl
- cmt01a
- cmt02_pt
- coxt01
Expand Down
3 changes: 3 additions & 0 deletions man/ael01_nollt.Rd

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

3 changes: 3 additions & 0 deletions man/ael02.Rd

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

3 changes: 3 additions & 0 deletions man/ael03.Rd

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

68 changes: 68 additions & 0 deletions man/cml02a_gl.Rd

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

3 changes: 3 additions & 0 deletions man/std_listing.Rd

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

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

Code
cat(export_as_txt(res, lpp = 100, cpp = 110))
Output
ATC Class Level 2 WHODrug Preferred Name Investigator-Specified Treatment Term
——————————————————————————————————————————————————————————————————————————————————
ATCCLAS2 A medname A_1/3 A_1/3
medname A_2/3 A_2/3
medname A_3/3 A_3/3
ATCCLAS2 A p2 medname A_3/3 A_3/3
ATCCLAS2 B medname B_1/4 B_1/4
medname B_2/4 B_2/4
medname B_3/4 B_3/4
medname B_4/4 B_4/4
ATCCLAS2 B p2 medname B_1/4 B_1/4
medname B_2/4 B_2/4
ATCCLAS2 B p3 medname B_1/4 B_1/4
medname B_2/4 B_2/4
ATCCLAS2 C medname C_1/2 C_1/2
medname C_2/2 C_2/2
ATCCLAS2 C p2 medname C_1/2 C_1/2
medname C_2/2 C_2/2
ATCCLAS2 C p3 medname C_2/2 C_2/2

# cml02a_gl works with missing data

Code
cat(export_as_txt(res, lpp = 100, cpp = 110))
Output
ATC Class Level 2 WHODrug Preferred Name Investigator-Specified Treatment Term
————————————————————————————————————————————————————————————————————————————————————
No Coding Available medname A_1/3 A_1/3
medname A_2/3 A_2/3
medname A_3/3 A_3/3
medname B_1/4 B_1/4
medname B_2/4 B_2/4
medname B_3/4 B_3/4
medname B_4/4 B_4/4
medname C_1/2 C_1/2
medname C_2/2 C_2/2

# cml02a_gl functions work as expected

Code
cat(export_as_txt(res, lpp = 100, cpp = 110))
Output
ATC Class Level 2 WHODrug Preferred Name Investigator-Specified Treatment Term
——————————————————————————————————————————————————————————————————————————————————
ATCCLAS2 A medname A_1/3 A_1/3
medname A_2/3 A_2/3
medname A_3/3 A_3/3
ATCCLAS2 A p2 medname A_3/3 A_3/3
ATCCLAS2 B medname B_1/4 B_1/4
medname B_2/4 B_2/4
medname B_3/4 B_3/4
medname B_4/4 B_4/4
ATCCLAS2 B p2 medname B_1/4 B_1/4
medname B_2/4 B_2/4
ATCCLAS2 B p3 medname B_1/4 B_1/4
medname B_2/4 B_2/4
ATCCLAS2 C medname C_1/2 C_1/2
medname C_2/2 C_2/2
ATCCLAS2 C p2 medname C_1/2 C_1/2
medname C_2/2 C_2/2
ATCCLAS2 C p3 medname C_2/2 C_2/2

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

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

test_that("cml02a_gl works with missing data", {
proc_data <- syn_data
proc_data$adcm$ATC2 <- NA_character_
expect_silent(res <- run(cml02a_gl, proc_data))
expect_snapshot(cat(export_as_txt(res, lpp = 100, cpp = 110)))
})

# cml02a_gl functions ----

test_that("cml02a_gl functions work as expected", {
expect_silent(
res <- cml02a_gl_pre(syn_data) %>%
cml02a_gl_main()
)
expect_snapshot(cat(export_as_txt(res, lpp = 100, cpp = 110)))
})
Loading