Skip to content

Commit cdae598

Browse files
committed
Refactor as_rtf.fixed_design() to use S3 dispatch per method
1 parent 17cf1e1 commit cdae598

File tree

4 files changed

+268
-13
lines changed

4 files changed

+268
-13
lines changed

NAMESPACE

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ S3method(as_gt,design_fixed_rmst_summary)
1111
S3method(as_gt,design_fixed_summary)
1212
S3method(as_gt,gs_design)
1313
S3method(as_gt,simtrial_gs_wlr)
14-
S3method(as_rtf,fixed_design)
14+
S3method(as_rtf,design_fixed_ahr_summary)
15+
S3method(as_rtf,design_fixed_fh_summary)
16+
S3method(as_rtf,design_fixed_lf_summary)
17+
S3method(as_rtf,design_fixed_maxcombo_summary)
18+
S3method(as_rtf,design_fixed_mb_summary)
19+
S3method(as_rtf,design_fixed_milestone_summary)
20+
S3method(as_rtf,design_fixed_rd_summary)
21+
S3method(as_rtf,design_fixed_rmst_summary)
22+
S3method(as_rtf,design_fixed_summary)
1523
S3method(as_rtf,gs_design)
1624
S3method(summary,design_fixed_ahr)
1725
S3method(summary,design_fixed_fh)

R/as_rtf.R

Lines changed: 153 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,18 @@ as_rtf <- function(x, ...) {
9191
#' ) %>%
9292
#' summary() %>%
9393
#' as_rtf(file = tempfile(fileext = ".rtf"))
94-
as_rtf.fixed_design <- function(
94+
as_rtf.design_fixed_summary <- function(
9595
x,
96-
title = NULL,
97-
footnote = NULL,
96+
title,
97+
footnote,
9898
col_rel_width = NULL,
9999
orientation = c("portrait", "landscape"),
100100
text_font_size = 9,
101101
file,
102102
...) {
103103
orientation <- match.arg(orientation)
104-
method <- fd_method(x)
105-
title <- title %||% paste(fd_title(method), "{^a}")
106-
footnote <- footnote %||% paste("{^a}", fd_footnote(x, method))
104+
title <- paste(title, "{^a}")
105+
footnote <- paste("{^a}", footnote)
107106

108107
# set default column width
109108
n_row <- nrow(x)
@@ -146,6 +145,154 @@ as_rtf.fixed_design <- function(
146145
invisible(x)
147146
}
148147

148+
#' @rdname as_rtf
149+
#' @export
150+
as_rtf.design_fixed_ahr_summary <- function(
151+
x,
152+
title = "Fixed Design under AHR Method",
153+
footnote = "Power computed with average hazard ratio method.",
154+
col_rel_width = NULL,
155+
orientation = c("portrait", "landscape"),
156+
text_font_size = 9,
157+
file,
158+
...
159+
) {
160+
NextMethod("as_rtf", x, title = title, footnote = footnote,
161+
col_rel_width = col_rel_width, orientation = orientation,
162+
text_font_size = text_font_size, file = file, ...)
163+
}
164+
165+
#' @rdname as_rtf
166+
#' @export
167+
as_rtf.design_fixed_fh_summary <- function(
168+
x,
169+
title = "Fixed Design under Fleming-Harrington Method",
170+
footnote = paste(
171+
"Power for Fleming-Harrington test", substring(x$Design, 19),
172+
"using method of Yung and Liu."
173+
),
174+
col_rel_width = NULL,
175+
orientation = c("portrait", "landscape"),
176+
text_font_size = 9,
177+
file,
178+
...
179+
) {
180+
NextMethod("as_rtf", x, title = title, footnote = footnote,
181+
col_rel_width = col_rel_width, orientation = orientation,
182+
text_font_size = text_font_size, file = file, ...)
183+
}
184+
185+
#' @rdname as_rtf
186+
#' @export
187+
as_rtf.design_fixed_mb_summary <- function(
188+
x,
189+
title = "Fixed Design under Magirr-Burman Method",
190+
footnote = paste("Power for", x$Design, "computed with method of Yung and Liu."),
191+
col_rel_width = NULL,
192+
orientation = c("portrait", "landscape"),
193+
text_font_size = 9,
194+
file,
195+
...
196+
) {
197+
NextMethod("as_rtf", x, title = title, footnote = footnote,
198+
col_rel_width = col_rel_width, orientation = orientation,
199+
text_font_size = text_font_size, file = file, ...)
200+
}
201+
202+
#' @rdname as_rtf
203+
#' @export
204+
as_rtf.design_fixed_lf_summary <- function(
205+
x,
206+
title = "Fixed Design under Lachin and Foulkes Method",
207+
footnote = paste(
208+
"Power using Lachin and Foulkes method applied using expected",
209+
"average hazard ratio (AHR) at time of planned analysis."
210+
),
211+
col_rel_width = NULL,
212+
orientation = c("portrait", "landscape"),
213+
text_font_size = 9,
214+
file,
215+
...
216+
) {
217+
NextMethod("as_rtf", x, title = title, footnote = footnote,
218+
col_rel_width = col_rel_width, orientation = orientation,
219+
text_font_size = text_font_size, file = file, ...)
220+
}
221+
222+
#' @rdname as_rtf
223+
#' @export
224+
as_rtf.design_fixed_rd_summary <- function(
225+
x,
226+
title = "Fixed Design of Risk Difference under Farrington-Manning Method",
227+
footnote = paste(
228+
"Risk difference power without continuity correction using method of",
229+
"Farrington and Manning."
230+
),
231+
col_rel_width = NULL,
232+
orientation = c("portrait", "landscape"),
233+
text_font_size = 9,
234+
file,
235+
...
236+
) {
237+
NextMethod("as_rtf", x, title = title, footnote = footnote,
238+
col_rel_width = col_rel_width, orientation = orientation,
239+
text_font_size = text_font_size, file = file, ...)
240+
}
241+
242+
#' @rdname as_rtf
243+
#' @export
244+
as_rtf.design_fixed_maxcombo_summary <- function(
245+
x,
246+
title = "Fixed Design under MaxCombo Method",
247+
footnote = paste0(
248+
"Power for MaxCombo test with Fleming-Harrington tests ",
249+
substring(x$Design, 9), "."
250+
),
251+
col_rel_width = NULL,
252+
orientation = c("portrait", "landscape"),
253+
text_font_size = 9,
254+
file,
255+
...
256+
) {
257+
NextMethod("as_rtf", x, title = title, footnote = footnote,
258+
col_rel_width = col_rel_width, orientation = orientation,
259+
text_font_size = text_font_size, file = file, ...)
260+
}
261+
262+
#' @rdname as_rtf
263+
#' @export
264+
as_rtf.design_fixed_milestone_summary <- function(
265+
x,
266+
title = "Fixed Design under Milestone Method",
267+
footnote = paste("Power for", x$Design, "computed with method of Yung and Liu."),
268+
col_rel_width = NULL,
269+
orientation = c("portrait", "landscape"),
270+
text_font_size = 9,
271+
file,
272+
...
273+
) {
274+
NextMethod("as_rtf", x, title = title, footnote = footnote,
275+
col_rel_width = col_rel_width, orientation = orientation,
276+
text_font_size = text_font_size, file = file, ...)
277+
}
278+
279+
#' @rdname as_rtf
280+
#' @export
281+
as_rtf.design_fixed_rmst_summary <- function(
282+
x,
283+
title = "Fixed Design under Restricted Mean Survival Time Method",
284+
footnote = paste("Power for", x$Design, "computed with method of Yung and Liu."),
285+
col_rel_width = NULL,
286+
orientation = c("portrait", "landscape"),
287+
text_font_size = 9,
288+
file,
289+
...
290+
) {
291+
NextMethod("as_rtf", x, title = title, footnote = footnote,
292+
col_rel_width = col_rel_width, orientation = orientation,
293+
text_font_size = text_font_size, file = file, ...)
294+
}
295+
149296
check_rel_width <- function(width, n_col) {
150297
if (!is.null(width) && n_col != length(width)) stop(
151298
"The length of 'col_rel_width' (", length(width), ") differs with ",

R/summary.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ summary.fixed_design <- function(object, design_display, ...) {
8484

8585
# capitalize names
8686
ans <- cap_names(ans)
87-
ans <- add_class(ans, paste0("fixed_design"))
88-
ans <- add_class(ans, paste0("design_fixed_summary"))
87+
ans <- add_class(ans, "fixed_design")
88+
ans <- add_class(ans, "design_fixed_summary")
8989
ans <- add_class(ans, paste0("design_fixed_", object$design, "_summary"))
9090
return(ans)
9191
}

man/as_rtf.Rd

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

0 commit comments

Comments
 (0)