Skip to content

v0.8.0

Compare
Choose a tag to compare
@rich-iannone rich-iannone released this 16 Nov 23:24
· 4297 commits to master since this release
0acc7fb

New features

  • The new function sub_values() is here for subbing in arbitrary text in body cells, based on value, a regex, or a specialized function. It's like a supercharged find-and-replace for your gt table (#703). (#1066)

  • We want the setting of styles to be as easy as possible so, to that end, we've added a helpful new function: tab_style_body(). This function is a bit like sub_values() and a bit like tab_style(). The idea is that basic style attributes can be set based on values in the table body. We can target body cells though value, regex, and custom matching rules, and, apply styles to them and their surrounding context (e.g., styling an entire row or column wherein the match is found). The help file at ?tab_style_body provides copious examples w/ eye catching visuals (#863). (#1108)

  • The fmt_date(), fmt_time(), and fmt_datetime() functions have been improved so much, I don't even know where to begin. The fmt_datetime() function has an enhanced format argument that accepts CLDR-style formatting patterns (much more powerful and flexible than the strptime() patterns). The fmt_datetime() function will detect the pattern type given in format. The date_style and time_style arguments still exist but have been extended to accept more style keywords. There is now the concept of flexible date and time formats that are locale-aware (the locale argument is new to these functions). The info_date_style() and info_time_style() functions have been enhanced to give you display tables will all the style possibilities. All of this goodness extends to the vec_fmt_*() variants (vec_fmt_date(), vec_fmt_time(), and vec_fmt_datetime()). The documentation for all of this has been overhauled and provides many explanations and examples for your edification (#531, #1052). (#1053)

  • We can now have decimal alignment for numeric values and this made possible with the new cols_align_decimal() function. The function ensures that columns targeted are right-aligned, that accounting notation is supported, and that footnote marks don't interfere (#139, #144, #560, #673). (#1058, #1092; assist by the inimitable @steveputman!)

  • We can easily add a caption to a gt table (or replace an existing one) with the new and convenient tab_caption() function (#1048). (#1051, thank you @billdenney!)

  • So you've got a gt table and you want a value or two from that table to appear elsewhere in your R Markdown or Quarto document. Previously, you had to recreate it in some way but now you can use extract_cells()! That function will extract a vector of cell data from a gt_tbl object. The output vector will have the cell data formatted in the same way as the table. (#1045, #1047)

  • The as_raw_html() function is useful for generating an HTML string for table-in-HTML-email situations and for HTML embedding purposes (with that inline_css = TRUE option). While the CSS-inlining has been mostly fine, it had two major problems: (1) it was slow, and (2) the underlying R code was so underpowered that it just couldn't keep up with changes to our SCSS styles. This is now solved by integrating a package that uses the juice JS library (we call it juicyjuice!). This solution is far more performant and correct (#455, #540, #837, #858, #915, #1093). (#1114)

  • There's now padding around an HTML table! And you can even control the left/right (container.padding.x) and top/bottom (container.padding.y) padding values through tab_options()! This is very helpful since tables were way too close to paragraphs of text in rendered HTML documents produced by R Markdown and Quarto (#590, #1105). (#1116)

  • The table stub can now freely merge with other columns using any of the cols_merge*() collection of functions. This is great if you want to independently format the stub and other columns and then bring them together in interesting ways. (#1122)

  • We've added the ability to treat columns containing row names or group names as Markdown text. This provides the process_md argument in the gt() function. If this option is taken (example below) then the supplied names will be treated to ensure that there are unique IDs for later targeting (for tab_style(), tab_footnote(), etc.) (#694). (#1097)

    dplyr::tibble(x = c("**a**", "b", "*c*"), y = c("*A*", "*B*", "*B*"), z = 1:3) %>%
      gt(rowname_col = "x", groupname_col = "y", process_md = TRUE)
  • If you find yourself not knowing the ID values of certain cells in the table (sometimes necessary for adding footnotes, styles, etc.) the new tab_info() function can help! Use that with a gt object and you'll get an informative table that summarizes all of the table's ID values and their associated labels (#1102). (#1104)

  • Much of gt is about adding things to a table but what about doing the opposite (taking things away)? The new family of rm_*() functions (rm_header(), rm_stubhead(), rm_spanners(), rm_footnotes(), rm_source_notes(), and rm_caption()) let us safely remove parts of a gt table. This can be advantageous in those instances where one might obtain a gt table though other means (like from another pkg) but prefer to excise some parts of it (#790, #1005). (#1073)

  • The table stub column can now have its contents formatted with any of the fmt_*() functions. We also added the stub() helper function to help select the stub column (#747). (#1038)

  • The new formatter function fmt_roman() lets us easily format numbers to Roman numerals (either as uppercase or lowercase letters). The vec_fmt_roman() vector-formatting function was also introduced here. (#1035)

  • The data_color() function allows us to color the background of cells based on data, and gt smartly chooses a text color that provides the most contrast between text and background. We wanted to improve that feature so now data_color() has a contrast_algo argument that allows us to choose between two color contrast algorithms: "apca" (Accessible Perceptual Contrast Algorithm; new, and the default now) and "wcag" (Web Content Accessibility Guidelines). (#1062)

  • The accessibility of structurally-complicated gt tables (i.e., multi-level headings, irregular headers, row groups, etc.) was addressed by work that follows the W3C WAI (Web Accessibility Initiative) guidance. Now, screen readers can better describe gt tables with such complex structures (#926). (#988, thanks @jooyoungseo!)

Minor improvements and bug fixes

  • The docx output format is now better detected in R Markdown and Quarto (#1040). (#1084, thanks @cderv!)

  • Replaced all match.arg() calls with rlang's match_arg() for better error output (#672). (#1099, thanks @mojister!)

  • Project website improvements; we now have a doublet of sites: (1) https://gt.rstudio.com and (2) https://gt.rstudio.com/dev (#1074, thanks @ddsjoberg!)

  • The dependency on the stringr package has been removed by replacing the remaining stringr-based function calls in the package with base-R equivalents. (#1043)