Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
1b7a759
Add digits argument to h_tbl_median_surv and control_surv_med_annot
Melkiades May 20, 2026
825bd37
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] May 20, 2026
5f0efdf
lintr
Melkiades May 20, 2026
483ecd4
snap
Melkiades May 20, 2026
2bc03d1
Replace deprecated case_match() with recode_values() in test
Melkiades May 20, 2026
0d1d5c6
Merge branch 'main' into copilot/expose-digits-argument-h-tbl-median-…
Melkiades May 21, 2026
77003a9
snaps
Melkiades May 21, 2026
0d02b15
Merge branch 'main' into copilot/expose-digits-argument-h-tbl-median-…
Melkiades Jun 10, 2026
9e20fe7
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] Jun 10, 2026
c06ab3f
Resolve merge conflicts: expose digits parameter for h_tbl_median_surv
Copilot Jul 9, 2026
54cf3da
Resolve conflicts by taking new implementation
Copilot Jul 9, 2026
d3d144b
Add tests and snapshots for digits parameter
Copilot Jul 9, 2026
1a35602
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] Jul 9, 2026
3ee8866
Merge branch 'main' into copilot/expose-digits-argument-h-tbl-median-…
shajoezhu Jul 10, 2026
b502f28
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] Jul 10, 2026
9d675cb
Merge branch 'main' into copilot/expose-digits-argument-h-tbl-median-…
shajoezhu Jul 13, 2026
c53ea36
fix: handle pkgdown cran_link network failures in CI via .Rprofile patch
Copilot Jul 13, 2026
f660bea
fix: correct control_coxph_annot to not expose digits and update snap…
Copilot Jul 13, 2026
97a175a
Merge branch 'main' into copilot/expose-digits-argument-h-tbl-median-…
shajoezhu Jul 13, 2026
9028697
Merge branch 'main' into copilot/expose-digits-argument-h-tbl-median-…
shajoezhu Jul 13, 2026
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
18 changes: 18 additions & 0 deletions .Rprofile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
if (Sys.getenv("GITHUB_ACTIONS") == "true") {
local({
# Patch pkgdown's cran_link() to handle network failures gracefully.
# In restricted CI environments, cloud.r-project.org may be unreachable,
# causing pkgdown::build_site() to fail with a connection error. Since
# pkgdown 2.x removed the pkgdown.internet option, this wraps cran_link()
# in a tryCatch so that connection errors return NULL (no CRAN link shown
# in the sidebar) rather than halting the build.
if (requireNamespace("pkgdown", quietly = TRUE)) {
.orig_cran_link <- utils::getFromNamespace("cran_link", "pkgdown")
utils::assignInNamespace(
"cran_link",
function(pkg) tryCatch(.orig_cran_link(pkg), error = function(e) NULL),
ns = "pkgdown"
)
}
})
}
6 changes: 5 additions & 1 deletion R/g_km.R
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,11 @@ g_km <- function(df,

# add median survival time annotation table
if (annot_surv_med) {
surv_med_tbl <- h_tbl_median_surv(fit_km = fit_km, armval = armval)
surv_med_tbl <- h_tbl_median_surv(
fit_km = fit_km,
armval = armval,
digits = control_annot_surv_med[["digits"]] %||% 4
)
bg_fill <- if (isTRUE(control_annot_surv_med[["fill"]])) "#00000020" else control_annot_surv_med[["fill"]]

gg_surv_med <- df2gg(surv_med_tbl, font_size = font_size, colwidths = c(1, 1, 2), bg_fill = bg_fill) +
Expand Down
24 changes: 17 additions & 7 deletions R/h_km.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,22 @@ NULL
#' table can be added in [g_km()] by setting `annot_surv_med=TRUE`, and can be configured using the
#' `control_surv_med_annot()` function by setting it as the `control_annot_surv_med` argument.
#'
#' @param digits (`integer(1)`)\cr number of significant digits for median survival
#' time and confidence interval values. Defaults to `4`.
#'
#' @examples
#' control_surv_med_annot()
#' control_surv_med_annot(digits = 2)
#'
#' @export
control_surv_med_annot <- function(x = 0.8, y = 0.85, w = 0.32, h = 0.16, fill = TRUE) {
control_surv_med_annot <- function(x = 0.8, y = 0.85, w = 0.32, h = 0.16, fill = TRUE, digits = 4) {
assert_proportion_value(x)
assert_proportion_value(y)
assert_proportion_value(w)
assert_proportion_value(h)
checkmate::assert_int(digits, lower = 1)

list(x = x, y = y, w = w, h = h, fill = fill)
list(x = x, y = y, w = w, h = h, fill = fill, digits = digits)
}

#' @describeIn control_annot Control function for formatting the Cox-PH annotation table. This annotation table can be
Expand All @@ -50,8 +55,9 @@ control_surv_med_annot <- function(x = 0.8, y = 0.85, w = 0.32, h = 0.16, fill =
control_coxph_annot <- function(x = 0.29, y = 0.51, w = 0.4, h = 0.125, fill = TRUE, ref_lbls = FALSE) {
checkmate::assert_logical(ref_lbls, any.missing = FALSE)

res <- c(control_surv_med_annot(x = x, y = y, w = w, h = h), list(ref_lbls = ref_lbls))
res
base <- control_surv_med_annot(x = x, y = y, w = w, h = h, fill = fill)
base[["digits"]] <- NULL
c(base, list(ref_lbls = ref_lbls))
}

#' Helper function to calculate x-tick positions
Expand Down Expand Up @@ -117,6 +123,8 @@ h_xticks <- function(data, xticks = NULL, max_time = NULL) {
#' Transform a survival fit to a table with groups in rows characterized by N, median and confidence interval.
#'
#' @inheritParams h_data_plot
#' @param digits (`integer(1)`)\cr number of significant digits for median and CI values.
#' Defaults to `4`.
#'
#' @return A summary table with statistics `N`, `Median`, and `XX% CI` (`XX` taken from `fit_km`).
#'
Expand All @@ -130,9 +138,11 @@ h_xticks <- function(data, xticks = NULL, max_time = NULL) {
#' data = adtte
#' )
#' h_tbl_median_surv(fit_km = fit)
#' h_tbl_median_surv(fit_km = fit, digits = 2)
#'
#' @export
h_tbl_median_surv <- function(fit_km, armval = "All") {
h_tbl_median_surv <- function(fit_km, armval = "All", digits = 4) {
checkmate::assert_int(digits, lower = 1)
y <- if (is.null(fit_km$strata)) {
as.data.frame(t(summary(fit_km)$table), row.names = armval)
} else {
Expand All @@ -143,9 +153,9 @@ h_tbl_median_surv <- function(fit_km, armval = "All") {
}
conf.int <- summary(fit_km)$conf.int # nolint
y$records <- round(y$records)
y$median <- signif(y$median, 4)
y$median <- signif(y$median, digits)
y$`CI` <- paste0(
"(", signif(y[[paste0(conf.int, "LCL")]], 4), ", ", signif(y[[paste0(conf.int, "UCL")]], 4), ")"
"(", signif(y[[paste0(conf.int, "LCL")]], digits), ", ", signif(y[[paste0(conf.int, "UCL")]], digits), ")"
)
stats::setNames(
y[c("records", "median", "CI")],
Expand Down
13 changes: 12 additions & 1 deletion man/control_annot.Rd

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

6 changes: 5 additions & 1 deletion man/h_tbl_median_surv.Rd

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

13 changes: 13 additions & 0 deletions tests/testthat/_snaps/h_km.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
$fill
[1] TRUE

$digits
[1] 4


# control_coxph_annot works with default settings

Expand Down Expand Up @@ -98,6 +101,16 @@
ARM B 73 727.8 (555.8, 1156)
ARM C 58 632.3 (393, 1001)

# h_tbl_median_surv works with custom digits parameter

Code
res
Output
N Median 95% CI
ARM A 69 970 (690, 1600)
ARM B 73 730 (560, 1200)
ARM C 58 630 (390, 1000)

# h_tbl_coxph_pairwise estimates HR, CI and pvalue

Code
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-h_km.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ testthat::test_that("h_tbl_median_surv estimates median survival time with CI",
testthat::expect_snapshot(res)
})

testthat::test_that("h_tbl_median_surv works with custom digits parameter", {
result <- h_tbl_median_surv(fit_km = test_fit, digits = 2)

res <- testthat::expect_silent(result)
testthat::expect_snapshot(res)
})

testthat::test_that("h_tbl_coxph_pairwise estimates HR, CI and pvalue", {
df <- tern_ex_adtte |>
filter(PARAMCD == "OS") |>
Expand Down
Loading