Skip to content

Simplify lt.R using lt predicate selectors and spanner auto-reorder (next lt release) #373

Description

@yihui

Context

PR #372 replaced gt with lt for summary tables. To work with the current CRAN lt (0.4), R/lt.R had to work around two lt limitations:

  1. No pattern-based column selection — spanner/label columns are enumerated with grep("_time$", names(x), value = TRUE) etc.
  2. Spanner columns had to be listed in visual (post-lt_move) order — lt matched a spanner to the visual position of its first column and spanned the next length(columns) cells, so a mismatched order silently dropped later spanners (this caused the "Probability of crossing efficacy bounds under H1" spanner to go missing; fixed in 76a63ca by listing columns in explicit asy-before-sim order).

Both limitations are addressed in the next lt version (merged upstream in yihui/lt#5 plus follow-up yihui/lt@50c09bc):

  • Predicate formulas: columns = ~ endsWith(., "_time"), ~ grepl("_prob$", .), ~ . (all columns), etc.
  • lt_label() accepts a single named list/vector of labels (no more do.call() splice).
  • Spanner columns auto-reordered to body order at render, so their listed order no longer matters (predicate selectors are safe for spanners too).

Task (do this once lt >= that version is on CRAN)

In R/lt.R:

  • Replace the grep(..., names(x), value = TRUE) spanner enumerations (and the explicit c("asy_time", "sim_time") ordering added in 76a63ca) with predicate selectors, e.g. lt_spanner(Time ~ endsWith(., "_time")). Spanner auto-reorder means order no longer needs hand-managing.
  • Replace the do.call(lt::lt_label, c(list(ans), labels)) splice with ans |> lt::lt_label(labels) (single named vector). See the review suggestion on PR Replace gt with lt for summary tables (#371) #372.

In vignettes/discrepancy-between-simtrial-and-survival.Rmd:

  • Replace lt_format(columns = names(fr)[sapply(fr, is.numeric)], ...) with the everything() equivalent columns = ~ ..

In DESCRIPTION:

  • Bump the lt Imports version constraint to the release that ships these features (lt (>= X.Y.Z)).

References

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions