Skip to content

Replace gt dependency with lt#629

Draft
yihui wants to merge 5 commits into
mainfrom
replace-gt-with-lt
Draft

Replace gt dependency with lt#629
yihui wants to merge 5 commits into
mainfrom
replace-gt-with-lt

Conversation

@yihui
Copy link
Copy Markdown
Collaborator

@yihui yihui commented May 21, 2026

Summary

  • Remove the gt package from Imports and replace with the lightweight lt package
  • New as_lt() generic + S3 methods for fixed_design_summary and gs_design_summary, fully replacing as_gt()
  • All 14 vignettes updated to use lt functions (lt(), lt_header(), lt_spanner(), lt_format(), lt_footnote(), lt_note(), lt_cols_label())
  • README.Rmd updated to use knitr::kable() for GitHub rendering and show lt API in code examples
  • Tests updated for lt_tbl assertions

New lt features required (committed in yihui/lt)

  • lt_cols_label(): rename column display headers without modifying data frame columns
  • lt_footnote(match = "starts_with"): target all row groups whose label starts with a prefix (used for "Analysis: ..." groups)

Migration mapping

gt lt
gt::gt(x) lt(x)
group_by(col) |> gt() lt(x, row_group = "col")
tab_header(title, subtitle) lt_header(title, subtitle)
tab_spanner(label, columns) lt_spanner(label, columns)
fmt_number(columns, decimals) lt_format(columns, decimals)
tab_footnote(fn, cells_column_labels(col)) lt_footnote(text, "column", columns)
tab_footnote(fn) (no location) lt_note(text)
cols_label(a = "A") lt_cols_label(a = "A")

Test plan

  • as_lt() unit tests pass for fixed and GS designs
  • All design types render correctly (fixed_ahr, gs_ahr, gs_wlr, gs_rd)
  • Visual comparison with gt output confirms structural equivalence
  • Non-binding design body footnote renders correctly
  • Custom footnotes (colname, title, analysis, spanner) all work
  • R CMD check passes
  • All vignettes build without error

🤖 Generated with Claude Code

yihui and others added 4 commits May 21, 2026 14:05
Remove the gt package dependency entirely and use the lightweight lt
package for table rendering. This reduces install weight and aligns
with the project's move toward minimal dependencies.

Changes:
- New as_lt() generic + methods replacing as_gt()
- All vignettes updated: gt() → lt(), tab_header() → lt_header(),
  fmt_number() → lt_format(), tab_spanner() → lt_spanner(),
  tab_footnote() → lt_footnote()/lt_note(), cols_label() → lt_cols_label()
- README.Rmd: use knitr::kable() for GitHub rendering
- DESCRIPTION: gt removed from Imports, lt added
- Tests updated for lt_tbl assertions

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
lt requires character strings for column names (unlike gt's tidy-select).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@yihui yihui marked this pull request as draft May 21, 2026 19:07
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@jdblischak jdblischak left a comment

Choose a reason for hiding this comment

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

When I run the tests locally, I get two failures:

library("testit")
test_pkg()
## Error: -- Assertion failed: as_lt: footnote=FALSE removes footnote --
##    1. count_footnotes(z1) (LHS) ==>
##        int 0
##       ----------
##        int 1
##       <== (RHS) 1L
##       count_footnotes(z1) %==% 1L is not TRUE but FALSE at tests/testit/test-developer-as_lt.R#14
##    2. count_footnotes(z1) (LHS) ==>
##        int 0
##       ----------
##        int 2
##       <== (RHS) 2L
##       count_footnotes(z1) %==% 2L is not TRUE but FALSE at tests/testit/test-developer-as_lt.R#22

sessioninfo::package_info(c("gsDesign2", "lt"), dependencies = FALSE)
##  package   * version date (UTC) lib source
##  gsDesign2 * 1.1.8   2026-05-28 [1] local
##  lt          0.0.7   2026-05-28 [1] Github (yihui/lt@e485eb6)
##
##  [1] C:/Users/john/AppData/Local/R/win-library/4.4
##  [2] C:/Program Files/R/R-4.4.3/library
##  * ── Packages attached to the search path.

Comment thread R/as_gt.R
#' @export
as_gt <- function(x, ...) {
UseMethod("as_gt", x)
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since as_gt() is an exported function, should we have at least one release where it is marked as deprecated before we actually remove it?

#' @export
as_gt <- function(x, ...) {
  .Deprecated("as_lt")
  UseMethod("as_gt", x)
}

@jdblischak
Copy link
Copy Markdown
Collaborator

And for a visual comparison, below is what I see in the RStudio Viewer on Windows for the last table produced by example("as_gt") or example("as_lt")

as_gt()

image

as_lt()

image

@yihui
Copy link
Copy Markdown
Collaborator Author

yihui commented May 28, 2026

@jdblischak Thanks for the feedback! This PR is still a draft, and all issues will be addressed. The final goal is to eliminate most (if not all) visual differences. I'll ping you and Yujie when the PR is ready for review.

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.

2 participants