Skip to content

Commit debda30

Browse files
Merge pull request #350 from Merck/auto-cut
Create cut functions automatically based on the design object
2 parents ee9d988 + edc4ba8 commit debda30

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

R/sim_gs_n.R

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
#' Importantly, note that the simulated data set is always passed as the first
3838
#' positional argument to each test function provided.
3939
#' @param cut A list of cutting functions created by [create_cut()], see
40-
#' examples.
40+
#' examples. Alternatively, if cut is \code{NULL} (the default) and a design
41+
#' object is provided via the argument `original_design`, the cut functions
42+
#' are automatically created from this object.
4143
#' @param original_design A design object from the gsDesign2 package, which is required when users
4244
#' want to calculate updated bounds. The default is NULL leaving the updated bounds uncalculated.
4345
#' @param ia_alpha_spending Spend alpha at interim analysis based on
@@ -319,6 +321,10 @@ sim_gs_n <- function(
319321
message("The updated bound is currently only provided for logrank test.")
320322
}
321323

324+
# Create cut functions from the original design (if provided) by default
325+
if (is.null(cut)) cut <- cut_from_design(original_design)
326+
if (is.null(cut)) stop("Please provide the cutting for each analysis.")
327+
322328
# parallel computation message for backends ----
323329
if (!is(plan(), "sequential")) {
324330
# future backend
@@ -505,6 +511,19 @@ create_cut <- function(...) {
505511
}
506512
}
507513

514+
# Create cut functions from the design object `x`, e.g., gsDesign2::gs_design_ahr()
515+
cut_from_design <- function(x) {
516+
if (is.null(x)) return()
517+
k <- nrow(x$analysis)
518+
lapply(seq_len(k), function(i) {
519+
if (is.null(x$input$analysis_time)) {
520+
create_cut(target_event_overall = x$analysis$event[i])
521+
} else {
522+
create_cut(planned_calendar_time = x$analysis$time[i])
523+
}
524+
})
525+
}
526+
508527
#' Create a cutting test function
509528
#'
510529
#' Create a cutting test function for use with [sim_gs_n()]

man/sim_gs_n.Rd

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)