Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Imports:
dplyr (>= 1.1.0),
ggplot2 (>= 3.1.1),
graphics,
gt,
lt,
methods,
r2rtf,
rlang,
Expand All @@ -44,6 +44,8 @@ Suggests:
testthat,
utils,
vdiffr
Remotes:
yihui/lt
VignetteBuilder:
knitr
Config/roxygen2/version: 8.0.0
9 changes: 1 addition & 8 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Generated by roxygen2: do not edit by hand

S3method(as_gt,gsBinomialExactTable)
S3method(as_rtf,gsBinomialExactTable)
S3method(as_rtf,gsBoundSummary)
S3method(as_table,gsBinomialExact)
S3method(lt::lt,gsBinomialExactTable)
S3method(plot,binomialSPRT)
S3method(plot,gsBinomialExact)
S3method(plot,gsDesign)
Expand Down Expand Up @@ -140,13 +140,6 @@ importFrom(graphics,plot)
importFrom(graphics,points)
importFrom(graphics,strwidth)
importFrom(graphics,text)
importFrom(gt,cols_label)
importFrom(gt,fmt_number)
importFrom(gt,fmt_percent)
importFrom(gt,gt)
importFrom(gt,html)
importFrom(gt,tab_header)
importFrom(gt,tab_spanner)
importFrom(methods,is)
importFrom(r2rtf,rtf_body)
importFrom(r2rtf,rtf_colheader)
Expand Down
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# gsDesign (development version)

## Major changes

- The (heavy) **gt** dependency has been replaced with the lightweight **lt**
package. The `as_gt()` function is deprecated in favor of `lt::lt()`. An S3
method for `lt()` is provided for `gsBinomialExactTable` objects, and all
vignettes now use lt functions (`lt()`, `lt_header()`, `lt_spanner()`,
`lt_format()`, `lt_footnote()`, `lt_note()`, `lt_label()`, `lt_align()`,
`lt_group()`). There are no significant visual changes in the HTML tables.

# gsDesign 3.10.0

## New features
Expand Down
83 changes: 9 additions & 74 deletions R/as_gt.R
Original file line number Diff line number Diff line change
@@ -1,82 +1,17 @@
#' Convert a summary table object to a gt object
#' Deprecated: use lt() instead
#'
#' Convert a summary table object created with \code{\link{as_table}}
#' to a \code{gt_tbl} object; currently only implemented for
#' \code{\link{gsBinomialExact}}.
#' \code{as_gt()} is deprecated; use \code{\link[lt]{lt}()} instead.
#'
#' @param x Object to be converted.
#' @param ... Other parameters that may be specific to the object.
#' @param ... Additional arguments passed to \code{\link[lt]{lt}()}.
#'
#' @return A \code{gt_tbl} object that may be extended by overloaded versions of
#' \code{\link{as_gt}}.
#' @return An \code{lt_tbl} object.
#'
#' @seealso \code{vignette("binomialSPRTExample")}
#'
#' @details
#' Currently only implemented for \code{\link{gsBinomialExact}} objects.
#' Creates a table to summarize an object.
#' For \code{\link{gsBinomialExact}}, this summarized operating characteristics
#' across a range of effect sizes.
#'
#' @export
#'
#' @examples
#' safety_design <- binomialSPRT(
#' p0 = .04, p1 = .1, alpha = .04, beta = .2, minn = 4, maxn = 75
#' )
#' safety_power <- gsBinomialExact(
#' k = length(safety_design$n.I),
#' theta = seq(.02, .16, .02),
#' n.I = safety_design$n.I,
#' a = safety_design$lower$bound,
#' b = safety_design$upper$bound
#' )
#' safety_power |>
#' as_table() |>
#' as_gt(
#' theta_label = gt::html("Underlying<br>AE rate"),
#' prob_decimals = 3,
#' bound_label = c("low rate", "high rate")
#' )
as_gt <- function(x, ...) UseMethod("as_gt")

#' @rdname as_gt
#'
#' @param title Table title.
#' @param subtitle Table subtitle.
#' @param theta_label Label for theta.
#' @param bound_label Label for bounds.
#' @param prob_decimals Number of decimal places for probability of crossing.
#' @param en_decimals Number of decimal places for expected number of
#' observations when bound is crossed or when trial ends without crossing.
#' @param rr_decimals Number of decimal places for response rates.
#'
#' @importFrom gt gt tab_spanner cols_label html fmt_number fmt_percent tab_header
#' @seealso \code{\link{lt-methods}}
#'
#' @export
as_gt.gsBinomialExactTable <- function(
x,
...,
title = "Operating Characteristics for the Truncated SPRT Design",
subtitle = "Assumes trial evaluated sequentially after each response",
theta_label = html("Underlying<br>response rate"),
bound_label = c("Futility bound", "Efficacy bound"),
prob_decimals = 2,
en_decimals = 1,
rr_decimals = 0) {
out_gt <- x |>
gt() |>
tab_spanner(label = "Probability of crossing", columns = c(Lower, Upper)) |>
cols_label(
theta = theta_label,
Lower = bound_label[1],
Upper = bound_label[2],
en = html("Average<br>sample size")
) |>
fmt_number(columns = c(Lower, Upper), decimals = prob_decimals) |>
fmt_number(columns = en, decimals = en_decimals) |>
fmt_percent(columns = theta, decimals = rr_decimals) |>
tab_header(title = title, subtitle = subtitle)

out_gt
as_gt <- function(x, ...) {
.Deprecated("lt", package = "lt",
msg = "as_gt() is deprecated; please use lt::lt() instead.")
lt::lt(x, ...)
}
72 changes: 72 additions & 0 deletions R/as_lt.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#' Convert a summary table object to an lt table
#'
#' Convert a summary table object created with \code{\link{as_table}}
#' to an \code{lt_tbl} object; currently only implemented for
#' \code{\link{gsBinomialExact}}.
#'
#' @param data Object to be converted.
#' @param ... Other parameters that may be specific to the object.
#' @param title Table title.
#' @param subtitle Table subtitle.
#' @param theta_label Label for theta.
#' @param bound_label Label for bounds.
#' @param prob_decimals Number of decimal places for probability of crossing.
#' @param en_decimals Number of decimal places for expected number of
#' observations when bound is crossed or when trial ends without crossing.
#' @param rr_decimals Number of decimal places for response rates.
#'
#' @return An \code{lt_tbl} object.
#'
#' @seealso \code{vignette("binomialSPRTExample")}
#'
#' @details
#' Currently only implemented for \code{\link{gsBinomialExact}} objects.
#' Creates a table to summarize an object.
#' For \code{\link{gsBinomialExact}}, this summarized operating characteristics
#' across a range of effect sizes.
#'
#' @name lt-methods
#'
#' @examples
#' safety_design <- binomialSPRT(
#' p0 = .04, p1 = .1, alpha = .04, beta = .2, minn = 4, maxn = 75
#' )
#' safety_power <- gsBinomialExact(
#' k = length(safety_design$n.I),
#' theta = seq(.02, .16, .02),
#' n.I = safety_design$n.I,
#' a = safety_design$lower$bound,
#' b = safety_design$upper$bound
#' )
#' safety_power |>
#' as_table() |>
#' lt::lt(
#' theta_label = I("Underlying<br>AE rate"),
#' prob_decimals = 3,
#' bound_label = c("low rate", "high rate")
#' )
#'
#' @exportS3Method lt::lt
lt.gsBinomialExactTable <- function(
data,
...,
title = "Operating Characteristics for the Truncated SPRT Design",
subtitle = "Assumes trial evaluated sequentially after each response",
theta_label = I("Underlying<br>response rate"),
bound_label = c("Futility bound", "Efficacy bound"),
prob_decimals = 2,
en_decimals = 1,
rr_decimals = 0) {
lt::lt(as.data.frame(data), ...) |>
lt::lt_spanner(label = "Probability of crossing", columns = c("Lower", "Upper")) |>
lt::lt_label(
theta = theta_label,
Lower = bound_label[1],
Upper = bound_label[2],
en = I("Average<br>sample size")
) |>
lt::lt_format(columns = c("Lower", "Upper"), decimals = prob_decimals) |>
lt::lt_format(columns = "en", decimals = en_decimals) |>
lt::lt_format(columns = "theta", decimals = rr_decimals, percent = TRUE) |>
lt::lt_header(title = title, subtitle = subtitle)
}
2 changes: 1 addition & 1 deletion R/as_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#' )
#' b_power |>
#' as_table() |>
#' as_gt()
#' lt::lt()
as_table <- function(x, ...) UseMethod("as_table")

#' @rdname as_table
Expand Down
2 changes: 1 addition & 1 deletion R/globals.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
utils::globalVariables(
unique(
c(
# From `as_gt.gsBinomialExactTable()`
# From `lt.gsBinomialExactTable()`
c("Lower", "Upper", "en", "theta"),
# From `binomialPowerTable()`
c("pE")
Expand Down
2 changes: 1 addition & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ reference:
contents:
- as_table
- as_table.gsBinomialExact
- lt-methods
- as_gt
- as_gt.gsBinomialExactTable
- as_rtf
- as_rtf.gsBinomialExactTable

Expand Down
66 changes: 5 additions & 61 deletions man/as_gt.Rd

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

2 changes: 1 addition & 1 deletion man/as_table.Rd

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

Loading
Loading