Skip to content

Replace gt with lt for summary tables (#371) - #372

Open
yihui wants to merge 3 commits into
mainfrom
gt-to-lt-371
Open

Replace gt with lt for summary tables (#371)#372
yihui wants to merge 3 commits into
mainfrom
gt-to-lt-371

Conversation

@yihui

@yihui yihui commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

Replaces the heavy gt dependency with the lightweight lt package for rendering simulation summary tables, mirroring gsDesign2 PR #629 and gsDesign PR #282. Closes #371.

  • DESCRIPTION: add lt to Imports; keep gt in Suggests (still used by the deprecated as_gt()).
  • R/lt.R (new): re-export the lt() generic so lt() dispatches after loading only simtrial; port as_gt.simtrial_gs_wlr() to lt.simtrial_gs_wlr(). Since lt has no tidyselect, spanner/label columns are enumerated explicitly (grep()), and paired asymptotic/simulated columns are moved into contiguous blocks with lt_move() before applying lt_spanner(). Two-branch logic (compare_with_design) and the two-sided extra spanner are preserved.
  • R/as_gt.R: as_gt() generic now emits .Deprecated("lt", ...); as_gt.simtrial_gs_wlr() guards with assert_gt_installed(). Still returns a gt_tbl for one release. as_gt.fixed_design / as_gt.gs_design redirection shims left as-is.
  • Vignettes (7): converted gtlt calls; dropped library(lt) where only the re-exported lt() is used (rmst); switched requireNamespace("gt") gates to lt.
  • pkgdown: reference lt.simtrial_gs_wlr alongside as_gt.simtrial_gs_wlr.
  • NEWS: major-changes entry referencing Migrate to {lt} #371.

Verification

  • R CMD INSTALL + smoke test: after library(simtrial) alone, summary(...) |> lt() returns an lt_tbl for all three branches (no-design, one-sided, two-sided); as_gt() warns once and returns a gt_tbl.
  • Grep confirms no stray gt::/library(gt) outside the intentionally-kept deprecated as_gt() internals and doc references.

Known issue (pre-existing, not from this PR)

The test-unvalidated-sim_gs_n.R / test-unvalidated-summary.R parallel tests error with could not find function "convert_list_to_df_w_list_cols" / create_cut inside doFuture workers. This reproduces on the base branch and is a parallel-backend globals-detection issue, unrelated to the gt→lt change. Left for follow-up.

Follow-up

After merge, file an issue (like gsDesign2#663) to fully remove gt and as_gt() in a future release.

🤖 Generated with Claude Code

yihui and others added 3 commits September 2, 2026 15:15
Replace the heavy gt dependency with the lightweight lt package for
rendering simulation summary tables.

- Add lt to Imports; keep gt in Suggests for the deprecated as_gt().
- Add R/lt.R: re-export the lt() generic and port
  as_gt.simtrial_gs_wlr() to lt.simtrial_gs_wlr(). lt has no tidyselect,
  so spanner/label columns are enumerated explicitly and moved into
  contiguous blocks with lt_move().
- Deprecate as_gt(): the generic now emits .Deprecated("lt", ...) and the
  simtrial_gs_wlr method guards with assert_gt_installed(). It still
  returns a gt_tbl for one release.
- Convert all vignettes gt -> lt.
- pkgdown: reference lt.simtrial_gs_wlr; NEWS: add major-changes entry.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The raw output of sim_gs_n() carries the "simtrial_gs_wlr" class but lacks
the attributes added by summary(). Since the re-exported lt() generic now
dispatches to lt.simtrial_gs_wlr(), guard the method: when the object is
not a summary (no compare_with_design attribute), fall back to a plain lt
table, mirroring how bare gt() rendered it before. Fixes the vignette
build failure in CI.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Regenerate man pages so links to lt() and lt-methods resolve to the local
topics instead of gsDesign. The initial roxygen run predated the lt
re-export being loaded, so it mis-resolved [lt-methods] to
gsDesign:lt-methods, tripping the "error on warning" R CMD check.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Comment thread R/lt.R
Comment on lines +135 to +142
# lt has no tidyselect, so enumerate the columns of each spanner explicitly.
# Spanned columns must be contiguous, which is ensured by the lt_move() calls
# below (mirroring gt::cols_move() in as_gt()).
time_cols <- grep("_time$", names(x), value = TRUE)
event_cols <- grep("_event$", names(x), value = TRUE)
n_cols <- grep("_n$", names(x), value = TRUE)
upper_cols <- grep("_upper_prob$", names(x), value = TRUE)
lower_cols <- grep("_lower_prob$", names(x), value = TRUE)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part of code is ugly (although works), and will be improved in the next version of {lt}: yihui/lt#5

Comment thread R/lt.R
Comment on lines +182 to +183
do.call(lt::lt_label, c(list(ans), labels)) |>
lt::lt_header(title = title, subtitle = subtitle)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this ugly do.call() will also be gone with the next version of {lt}: yihui/lt#5

Suggested change
do.call(lt::lt_label, c(list(ans), labels)) |>
lt::lt_header(title = title, subtitle = subtitle)
ans |> lt::lt_label(labels) |>
lt::lt_header(title = title, subtitle = subtitle)

Comment thread R/lt.R
Comment on lines +127 to +130
lt::lt() |>
lt::lt_label(sim_time = "Time", sim_n = "N", sim_event = "Event", sim_upper_prob = "Crossing probability") |>
lt::lt_move(columns = c("sim_time", "sim_n", "sim_event"), after = "analysis") |>
lt::lt_header(title = title, subtitle = subtitle)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

used lt::lt() instead of lt() for consistency with the lt::lt_*() lines, although a bare lt() works

@yihui
yihui marked this pull request as ready for review September 2, 2026 21:35
@yihui
yihui requested a review from jdblischak September 2, 2026 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate to {lt}

1 participant