v0.9.0
New features
-
The
summary_rows()
andgrand_summary_rows()
functions have been rewritten extensively to allow more flexibility in providing aggregation information tofns
. The documentation for both functions will walk you through all the new ways you can express your aggregations. The formatting of cells in new summary rows is now easier thanks to the newfmt
argument. We can provide a single formatting expression or a number of them in a list. The dedicated documentation section for formatting can walk you through all of this. Furthermore, we now have the option to place summary rows at top or bottom of a group (insummary_rows()
) or table (ingrand_summary_rows()
) with the newside
argument (#177, #270, #292, #545, #581, #784, #785, #840). (#1159, #1171) -
The
data_color()
function has been completely overhauled to make it easier to use and also more powerful. It gains arows
argument to better constrain where the colorization should take place. Instead of having to use functions from scales to define the coloring scheme, you can now use themethod
argument to handle most cases (otherwise, the newfn
argument allows for a color-mapping function to be used). The newpalette
argument allows for flexible input of color palettes. One or more adjacent columns can receive the coloring treatment by way of the newtarget_columns
argument. Coloring can now also be applied in a row-wise fashion by usingdirection = "row"
. Despite all of these changes, older code should still work with the revamped function (#116, #633, #637, #1103, #1119). (#1147) -
We now have a much improved
cols_merge()
function! It has gained arows
argument for limiting which body cells get merged together. Thepattern
argument now has a more advanced syntax. It now has the following delimiters and rules: (1){ }
for arranging single column values in a row-wise fashion, and (2)<< >>
to surround spans of text that will be removed if any of the contained{ }
yields a missing value. The new<< >>
delimiters will help in cases whereNA
values are present and should be omitted during the merging process (#1167). (#1144, #1168) -
The
cols_label()
function has been improved by allowing formula expressions to be given to...
. With two-sided formulas (e.g.,<LHS> ~ <RHS>
), the left-hand side corresponds to selections of columns and the right-hand side evaluates to single-length values for the label to apply. Named arguments in the format of<column name> = <label>
are still also valid as input for simple mappings of column name to label text. Also, there's a.fn
argument, which takes a function to be applied to all provided label values (#1146). (#1255, #1256, #1265) -
Interactive HTML tables can now be generated in gt. Options for enabling interactive table rendering are available in
tab_options()
and also inopt_interactive()
. The collection ofuse_*
arguments inopt_interactive()
allow for control of pagination, global search, filtering, sorting, and more. The documentation withinopt_interactive()
demonstrates how to generate HTML tables with interactive elements (#207). (#902, #1252, #1261, #1278, #1280) -
A new function,
cols_label_with()
, has been added for relabeling columns via functions. It allows for such functions to be applied to arbitrary sets of columns, taking advantage of tidyselect. It's likedplyr::rename_with()
for your gt table, but it doesn't need unique names for labeling (#701). (#1158, thank you @christopherkenny!) -
We added
fmt_spelled_num()
andvec_fmt_spelled_num()
so that numeric values could be transformed to spelled out numbers. Any values from0
to100
can be spelled out according to a givenlocale
value. For example, the value23
will be rendered as"twenty-three"
if the locale is an English-language one (or, not provided at all); should a Swedish locale be provided (e.g.,"sv"
), the output will instead be"tjugotre"
. (#1198) -
The
fmt_index()
andvec_fmt_index()
functions were added in so that numeric values could undergo transformation to index values, which are usually based on letters (depending on thelocale
chosen). For example, the value5
will be rendered as"E"
if the locale is an English-language one. The characters chosen for indexing here are based on character sets intended for ordering (often leaving out characters with diacritical marks). (#1189) -
Should body cells contain URLs, the new
fmt_url()
function can be used to make them navigable links. There are several options provided that control how the links should be styled (conventional underline style or button-like text) (#609). (#1205, #1220, #1221) -
To more easily insert graphics into body cells, we have added the
fmt_image()
function. This allows for one or more images to be placed in the targeted cells. The cells need to contain some reference to an image file, either: (1) complete http/https or local paths to the files; (2) the file names, where a common path can be provided viapath
; or (3) a fragment of the file name, where thefile_pattern
argument helps to compose the entire file name and thepath
argument provides the path information. (#1240) -
The new
fmt_flag()
function helps with inserting a flag icon (or multiple) in body cells. The input cells need to contain 2-letter ISO 3166-1 country codes (e.g., Mauritius with the"MU"
country code). This function will parse the targeted body cells insert the appropriate flag icon. Multiple flags can be included per body cell by separating country codes with commas. (#1241, #1244, #1251) -
With
fmt_bins()
, you can format bin or interval syntax (returned fromcut()
) to a form that presents better in a display table. It's possible to format the values of the intervals with thefmt
argument, and, the separator can be modified with thesep
argument. (#1250) -
The new
fmt_auto()
function has been added to automatically apply formatting of various types in a way that best suits the data table provided. For example, the function will attempt to format numbers such that they are condensed to an optimal width, and, currency values can be detected (by currency codes embedded in the column name) and formatted in the correct way (#248). (#1176) -
Three
text_*()
functions were added to better enable transformations of formatted text in various table locations:text_replace()
,text_case_when()
, andtext_case_match()
. (#1238) -
We can use any of 15 system font stacks available in gt! These are families of themed system fonts that are widely available in different computer systems. Examples include 'System UI' (the default font stack), 'Humanist', and 'Neo-Grotesque'. The new helper function
system_fonts()
can be used to access the various font stack and is useful when specifyingfont
values in thecell_text()
function. Theopt_table_font()
function has been upgraded to include astack
argument (which accepts keywords for the different font stacks). (#1275) -
We now have a new family of functions that let you deal with a multitude of gt tables, all at once. You can create a
gt_group
object with multiple tables via thegt_group()
function, or, split a single table into multiple withgt_split()
. There are some advantages to having a group of tables bundled together like this. You could apply options that pertain to all tables yet still access the individual tables to give them their own specialized modifications. They all print together at once too! For HTML, each table will be separated by a line break whereas in paginated formats (e.g., RTF, Word, etc.) the tables are separated by page breaks. (#1216, #1219, #1226, #1248, #1249, #1262, #1264) -
There is now a choice of which Markdown engine to use for Markdown rendering (in
fmt_markdown()
andvec_fmt_markdown()
) and a default default choice. The markdown package can be chosen instead of commonmark to perform conversions of Markdown to HTML and LaTeX (and it's now the default). One of many benefits to this change is the parsing of subscripts (using~x~
) and superscripts (using^x^
) (#725). (#1254) -
Added the footnote formatting options
footnotes.spec_ref
andfootnotes.spec_ftr
intab_options()
and exposed these options further in a new function calledopt_footnote_spec()
. Specifications for footnote formatting can be produced for the footnote marks that alight to the targeted text within cells from various locations in the table, or, for the footnote marks that appear in the table footer. (#1268, #1271) -
The
towny
dataset was added. It provides a fun, population-based dataset with place names, URLs, coordinate information, and population figures with repetition (values for different census years). (#1184, #1199) -
The
metro
dataset is new. It has 308 rows, where each corresponds to a different Paris Metro station (#1231). -
The
rx_adsl
andrx_addv
datasets have been added. These clinical trial toy datasets are both featured in a new vignette that explains how gt can be used for table generation in the Pharma space (#1145, #1200; thank you @alex-lauer!).
Documentation enhancements
-
Addition of a new vignette (Case Study: Clinical Tables) that uses the
rx_adsl
andrx_addv
datasets. (#1145, #1217, #1224; all contributed by @alex-lauer) -
All examples in the documentation were modernized by using the
|>
instead of the%>%
. A lot of explanatory text was improved through rewriting. The ordering of documentation sections was improved. And functions that had very little documentation (liketext_transform()
) were greatly improved (#1087). (#1166, #1185, #1192) -
Several small documentation and housekeeping updates. (#1133, #1134, #1135, #1136, #1190, #1206, #1218, #1242, #1246, #1258, #1260, #1266, #1270, #1276, #1281)
Minor improvements and bug fixes
-
The
fmt_scientific()
andfmt_engineering()
(and theirvec_fmt_*()
analogues) now have aexp_style
argument for defining the exponent notation. By default this is"x10n"
but other options include using a single letter (e.g., "e", "E", etc.), a letter followed by a "1" to signal a minimum digit width of one, or "low-ten" for using a stylized "10" marker. These functions now also have theforce_sign_m
andforce_sign_n
arguments for forcing+
signs in the mantissa or the exponent. (#1178) -
We now have right-to-left (RTL) text handling and gt will automatically set the appropriate alignment for RTL text in HTML output. This is done through detection of RTL script characters. (#697). (#1202)
-
For any columns that are labeled (i.e., have a
label
attribute), gt will automatically use those labels as column labels (#656). (#1230) -
Tables in the Word output format now have much better Markdown support (#1057, #1067, #1204). (#1142, #1263, #1274)
-
Added the
"double"
option for a border style incell_borders()
(#1132). (#1137) -
The
countrypops
dataset was updated with recent (as of January 2023) World Bank data that revises population estimates and brings the final year up to 2021. All examples, tests, and articles using the dataset were also updated. (#1191) -
Fixed a conflict between
tab_spanner_delim()
andcols_label()
(#1130). (#1173) -
Added a fix for a
summary_rows()
problem where summary rows that were generated with only a single group would not display the summary rows at all. (#1188) -
HTML output tables no longer have two
<thead>
elements when they display a header and column labels (#1235). (#1237) -
Incorporated a CSS fix for superscripted footnote marks. Prior to the change, footnote marks were never styled within gt tables rendered in Quarto documents. (#1210)
-
We now remove knitr flags when saving an RTF file through the
gtsave()
function (#674). (#1153) -
Fixed LaTeX rendering of tables using the
xelatex
engine by removing the unneeded"amsmath"
LaTeX package from the default set of LaTeX dependencies. This set is now modifiable through thegt.latex_packages
option (#751). (#1279) -
Fixed some border-related issues for gt tables published in R Markdown and Quarto documents (#1120). (#1234)
-
Added the
quarto.use_bootstrap
andquarto.disable_processing
options intab_options()
to control whether Quarto will add Bootstrap classes to a gt table or ignore a gt table. (#1222, #1227) -
Fixed the unintended appearance of a bottom border in the column spanner row for some CSS environments. (#1209)
-
Fixed the SCSS class
.gt_footnote_marks
to ensure that the footnote mark is at a consistent height from the baseline in different CSS environments. (#1187) -
Fixed an error in the SCSS class
.gt_footnote
where the wrong types of padding were specified. (#1236) -
Added frequency levels to
cli_abort()
warnings throughout package (#1160). (#1169)