gtExtras icon indicating copy to clipboard operation
gtExtras copied to clipboard

return visibly

Open r2evans opened this issue 6 months ago • 0 comments

Prework

Suggested by the question at https://stackoverflow.com/questions/79677810/r-gtextras-gt-plt-bar-pct-fails-to-render/79677898#79677898, the return value from gt_plt_bar_pct() is invisible unlike gt_plt_bar(), which means that interactive exploration/use of the package may not automatically open a browser window/tab. Some assume that this quieter behavior means that nothing was done or something is wrong with their code. (While I've only seen one question about this invisible-behavior with gt-based code, it comes across SO often enough with ggplot2-based stuff, especially in rmarkdown/quarto docs.)

Proposal

I suggest giving the table-returning functions similar behavior: either all invisible() (which may spark many similar uninformed bug reports) or all visible.

If you opt to make gt_plt_bar_pct() (and any others that may be invisible) return visibly, then it should have no effect on unit-tests or CRAN tests.


Demo, from the SO question:

library(dplyr)
library(gt)
library(gtExtras)

base_tab <- dplyr::tibble(x = seq(1, 100, length.out = 6)) %>%
  dplyr::mutate(
    x_unscaled = x,
    x_scaled = x / max(x) * 100
  ) %>%
  gt()

base_tab %>%
  gt_plt_bar(x_unscaled, color = "purple", width = 100, scale = "percent")
### the bar plot is rendered and shown to the user

base_tab %>%
  gt_plt_bar_pct(column = x_unscaled, scaled = TRUE, fill = "forestgreen") %>%
  gt_plt_bar_pct(column = x_scaled, scaled = FALSE, labels = TRUE)
### the bar plots are not rendered, since the return value is invisible

r2evans avatar Jun 24 '25 20:06 r2evans