Skip to content

Commit

Permalink
Merge branch 'main' into 245_pdt02@main
Browse files Browse the repository at this point in the history
  • Loading branch information
edelarua authored Jan 20, 2023
2 parents 3f5db6a + 444e79e commit 4f50873
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 11 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Type: Package
Package: chevron
Title: Standard TLGs For Clinical Trials Reporting
Version: 0.1.1.9028
Date: 2023-01-16
Version: 0.1.1.9029
Date: 2023-01-20
Authors@R: c(
person("Benoit", "Falquet", , "[email protected]", role = c("aut", "cre")),
person("Adrian", "Waddell", , "[email protected]", role = "aut"),
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# chevron 0.1.1.9028
# chevron 0.1.1.9029

* First release with implementation of: `AET01`, `AET02`, `AET03`, `AET04`, `CMT01A`, `CMT02_PT`, `DMT01`, `DST01`, `DTHT01`, `EGT01`, `EGT02`, `EXT01`, `LBT01`, `MHT01`, `MNG01`, `VST01`, `VST02`.
19 changes: 15 additions & 4 deletions R/lbt01.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,17 @@ lbt01_1_lyt <- function(armvar,

# Create context dependent function.
n_fun <- sum(!is.na(x), na.rm = TRUE)
mean_sd_fun <- c(mean(x, na.rm = TRUE), sd(x, na.rm = TRUE))
median_fun <- median(x, na.rm = TRUE)
min_max_fun <- c(min(x), max(x))
if (n_fun == 0) {
mean_sd_fun <- c(NA, NA)
median_fun <- NA
min_max_fun <- c(NA, NA)
} else {
mean_sd_fun <- c(mean(x, na.rm = TRUE), sd(x, na.rm = TRUE))
median_fun <- median(x, na.rm = TRUE)
min_max_fun <- c(min(x), max(x))
}

# Identify context-
is_baseline <- .spl_context$value[2] == "BASELINE"
is_chg <- .var == "CHG"

is_baseline <- .spl_context$value[which(.spl_context$split == "AVISIT")] == "BASELINE"
Expand All @@ -141,6 +146,12 @@ lbt01_1_lyt <- function(armvar,
"Mean (SD)" = h_format_dec(format = "%f (%f)", digits = pcs + 1),
"Median" = h_format_dec(format = "%f", digits = pcs + 1),
"Min - Max" = h_format_dec(format = "%f - %f", digits = pcs)
),
.format_na_strs = list(
"n" = "NE",
"Mean (SD)" = "NE (NE)",
"Median" = "NE",
"Min - Max" = "NE - NE"
)
)
},
Expand Down
5 changes: 1 addition & 4 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -349,17 +349,14 @@ h_format_dec <- function(digits = NA, format = NA) {

if (is.na(format)) {
NULL

} else {

function(x, ...) {
checkmate::assert_numeric(x)

digit_string <- ifelse(is.na(digits), "", paste0(".", digits))
new_format <- gsub("%([a-z])", paste0("%", digit_string, "\\1"), format)
fun <- formatters::sprintf_format(new_format)

fun(x)
formatters::sprintf_format(new_format)(x)
}
}
}
20 changes: 20 additions & 0 deletions tests/testthat/_snaps/lbt01.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# lbt01_1 can handle n = 0 and outputs NE instead of infs and NAs

Code
res
Output
A: Drug X
Value at Visit
—————————————————————————————————————————————————————
Alanine Aminotransferase Measurement
BASELINE
n 0
Mean (SD) NE (NE)
Median NE
Min - Max NE - NE
WEEK 1 DAY 8
n 0
Mean (SD) NE (NE)
Median NE
Min - Max NE - NE

12 changes: 12 additions & 0 deletions tests/testthat/test-lbt01.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
test_that("lbt01_1 can handle n = 0 and outputs NE instead of infs and NAs", {
proc_data <- syn_data %>%
dm_zoom_to("adlb") %>%
filter(PARAM != "ALT" & ACTARM != "A: Drug X") %>%
dm_update_zoomed()

res <- expect_silent(
run(lbt01_1, proc_data, precision = c("ALT" = 0, "CRP" = 1))
)
res <- res[1:11, 1]
expect_snapshot(res)
})

0 comments on commit 4f50873

Please sign in to comment.