Skip to content

Commit 848cc45

Browse files
committed
Refactor as_gt.fixed_design() to use S3 dispatch per method
1 parent 6e6f37f commit 848cc45

File tree

4 files changed

+186
-11
lines changed

4 files changed

+186
-11
lines changed

NAMESPACE

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Generated by roxygen2: do not edit by hand
22

3-
S3method(as_gt,fixed_design)
3+
S3method(as_gt,design_fixed_ahr_summary)
4+
S3method(as_gt,design_fixed_fh_summary)
5+
S3method(as_gt,design_fixed_lf_summary)
6+
S3method(as_gt,design_fixed_maxcombo_summary)
7+
S3method(as_gt,design_fixed_mb_summary)
8+
S3method(as_gt,design_fixed_milestone_summary)
9+
S3method(as_gt,design_fixed_rd_summary)
10+
S3method(as_gt,design_fixed_rmst_summary)
11+
S3method(as_gt,design_fixed_summary)
412
S3method(as_gt,gs_design)
513
S3method(as_gt,simtrial_gs_wlr)
614
S3method(as_rtf,fixed_design)

R/as_gt.R

Lines changed: 104 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,113 @@ as_gt <- function(x, ...) {
7878
#' ) %>%
7979
#' summary() %>%
8080
#' as_gt()
81-
as_gt.fixed_design <- function(x, title = NULL, footnote = NULL, ...) {
82-
method <- fd_method(x)
83-
ans <- gt::gt(x) %>%
84-
gt::tab_header(title = title %||% fd_title(method)) %>%
81+
as_gt.design_fixed_summary <- function(x, title, footnote, ...) {
82+
gt::gt(x) %>%
83+
gt::tab_header(title = title) %>%
8584
gt::tab_footnote(
86-
footnote = footnote %||% fd_footnote(x, method),
85+
footnote = footnote,
8786
locations = gt::cells_title(group = "title")
8887
)
89-
return(ans)
88+
}
89+
90+
#' @rdname as_gt
91+
#' @export
92+
as_gt.design_fixed_ahr_summary <- function(
93+
x,
94+
title = "Fixed Design under AHR Method",
95+
footnote = "Power computed with average hazard ratio method.",
96+
...
97+
) {
98+
NextMethod("as_gt", x, title = title, footnote = footnote, ...)
99+
}
100+
101+
#' @rdname as_gt
102+
#' @export
103+
as_gt.design_fixed_fh_summary <- function(
104+
x,
105+
title = "Fixed Design under Fleming-Harrington Method",
106+
footnote = paste(
107+
"Power for Fleming-Harrington test", substring(x$Design, 19),
108+
"using method of Yung and Liu."
109+
),
110+
...
111+
) {
112+
NextMethod("as_gt", x, title = title, footnote = footnote, ...)
113+
}
114+
115+
#' @rdname as_gt
116+
#' @export
117+
as_gt.design_fixed_mb_summary <- function(
118+
x,
119+
title = "Fixed Design under Magirr-Burman Method",
120+
footnote = paste("Power for", x$Design, "computed with method of Yung and Liu."),
121+
...
122+
) {
123+
NextMethod("as_gt", x, title = title, footnote = footnote, ...)
124+
}
125+
126+
#' @rdname as_gt
127+
#' @export
128+
as_gt.design_fixed_lf_summary <- function(
129+
x,
130+
title = "Fixed Design under Lachin and Foulkes Method",
131+
footnote = paste(
132+
"Power using Lachin and Foulkes method applied using expected",
133+
"average hazard ratio (AHR) at time of planned analysis."
134+
),
135+
...
136+
) {
137+
NextMethod("as_gt", x, title = title, footnote = footnote, ...)
138+
}
139+
140+
#' @rdname as_gt
141+
#' @export
142+
as_gt.design_fixed_rd_summary <- function(
143+
x,
144+
title = "Fixed Design of Risk Difference under Farrington-Manning Method",
145+
footnote = paste(
146+
"Risk difference power without continuity correction using method of",
147+
"Farrington and Manning."
148+
),
149+
...
150+
) {
151+
NextMethod("as_gt", x, title = title, footnote = footnote, ...)
152+
}
153+
154+
#' @rdname as_gt
155+
#' @export
156+
as_gt.design_fixed_maxcombo_summary <- function(
157+
x,
158+
title = "Fixed Design under MaxCombo Method",
159+
footnote = paste0(
160+
"Power for MaxCombo test with Fleming-Harrington tests ",
161+
substring(x$Design, 9), "."
162+
),
163+
...
164+
) {
165+
NextMethod("as_gt", x, title = title, footnote = footnote, ...)
166+
}
167+
168+
#' @rdname as_gt
169+
#' @export
170+
as_gt.design_fixed_milestone_summary <- function(
171+
x,
172+
title = "Fixed Design under Milestone Method",
173+
footnote = paste("Power for", x$Design, "computed with method of Yung and Liu."),
174+
...
175+
) {
176+
NextMethod("as_gt", x, title = title, footnote = footnote, ...)
177+
}
178+
179+
#' @rdname as_gt
180+
#' @export
181+
as_gt.design_fixed_rmst_summary <- function(
182+
x,
183+
title = "Fixed Design under Restricted Mean Survival Time Method",
184+
footnote = paste("Power for", x$Design, "computed with method of Yung and Liu."),
185+
...
186+
) {
187+
NextMethod("as_gt", x, title = title, footnote = footnote, ...)
90188
}
91189

92190
get_method <- function(x, methods) intersect(methods, class(x))[1]

R/summary.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,12 @@ summary.fixed_design <- function(object, ...) {
100100

101101
# capitalize names
102102
ans <- cap_names(ans)
103-
ans <- add_class(ans, "fixed_design", x$design)
103+
ans <- add_class(ans, paste0("fixed_design"))
104+
ans <- add_class(ans, paste0("design_fixed_summary"))
105+
ans <- add_class(ans, paste0("design_fixed_", x$design, "_summary"))
104106
return(ans)
105107
}
106108

107-
108109
#' @rdname summary
109110
#'
110111
#' @param analysis_vars The variables to be put at the summary header of each analysis.

man/as_gt.Rd

Lines changed: 70 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)