Skip to content
master
Switch branches/tags
Code

Latest commit

* Add wip changes

* Update DESCRIPTION

* Update gt-package.Rd

* Update tab_create_modify.R

* Update tab_options.Rd

* Add default values for new options

* Add new `gt_stub_row_group` CSS class

* Allow row group label as column in stub

* Update helper-gt_attr_expectations.R

* `devtools::build_readme()` (GitHub Actions)

* Revise so that row group columns work well

* Add vertical-align rule for row group column text

* Change `seq()` to `seq_along()`

* Ensure that the stubhead cell is included

* Add `.gt_last_summary_row` CSS rules

* Rewrite `summary_row_tags_i()`

* Update several testthat tests

* Update test-summary_rows.R

* Update image.md

* Update summary_rows.md

* Add a comment

* More comments

* get_stub_layout now returns NULL if empty, not NA

* Don't duplicate `gt_summary_row` class

* Code review

* Handle case with unnamed groups

* Simplify some code paths

* Only obtain `boxh` if needed

* Remove unneeded statements

* Remove unneeded statements

* Fix join issue

* Incorporate row group columns in LaTeX rendering

* Update tests for LaTeX output

* Simplify obtaining column alignments

* Update utils_render_html.R

* Update utils_render_rtf.R

* Update tests and snapshot files

* Add snapshot tests

* Update utils_render_rtf.R

* Remove unneeded statement

* Modify default border width of row grp col

* Remove comment after verification of question

* Simplify creation of LaTeX body row vectors

* Remove redundant group labels down column

* htmlEscape more attr values in the table body

* Update test-tab_style.R

* Update group_column_label.md

* Update latex-08-using_summary_rows.Rmd

* Add horiz/vertical dividing lines for LaTeX tables

* Update group_column_label.md

* Update snapshot files

* Update test-l_table_parts.R

* Remove hborders within cells of group label col

* Add small double-line border in specific case

* Update snapshot test files

* Fix assembly of group_label_matrix

* Simplify create_group_dividers_l implementation

* Move group_rows and group_dividers closer to their usages

* Don't separate summary rows from group in specific case

* Modify conditional statement

* Make correction vector for dividers in LaTeX

* Soften separation of body/summary rows

* Remove dividing line in RTF output

* Tweak borders in row groups as columns

* Fix formatting of summary row label cells in LaTeX

* Draw border above summary rows in special case

* Tweak border appearance in RTF

* Update testthat tests

* Adjust trim of cmidrule

* Make correction to condition for border removal

* Update group_column_label.md

* Remove unneeded mutation of row group labels

* Remove unneeded condition

Co-authored-by: rich-iannone <rich-iannone@users.noreply.github.com>
Co-authored-by: Joe Cheng <joe@rstudio.com>
fcabb41

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
R
 
 
 
 
 
 
 
 
man
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

gt

CRAN status R build status Coverage status

With the gt package, anyone can make wonderful-looking tables using the R programming language. The gt philosophy: we can construct a wide variety of useful tables with a cohesive set of table parts. These include the table header, the stub, the column labels and spanner column labels, the table body, and the table footer.

It all begins with table data (be it a tibble or a data frame). You then decide how to compose your gt table with the elements and formatting you need for the task at hand. Finally, the table is rendered by printing it at the console, including it in an R Markdown document, or exporting to a file using gtsave(). Currently, gt supports the HTML, LaTeX, and RTF output formats.

The gt package is designed to be both straightforward yet powerful. The emphasis is on simple functions for the everyday display table needs. Here is a brief example of how to use gt to create a table from the included sp500 dataset:

library(gt)
library(tidyverse)
library(glue)

# Define the start and end dates for the data range
start_date <- "2010-06-07"
end_date <- "2010-06-14"

# Create a gt table based on preprocessed
# `sp500` table data
sp500 %>%
  filter(date >= start_date & date <= end_date) %>%
  select(-adj_close) %>%
  gt() %>%
  tab_header(
    title = "S&P 500",
    subtitle = glue("{start_date} to {end_date}")
  ) %>%
  fmt_date(
    columns = date,
    date_style = 3
  ) %>%
  fmt_currency(
    columns = c(open, high, low, close),
    currency = "USD"
  ) %>%
  fmt_number(
    columns = volume,
    suffixing = TRUE
  )

There are six datasets included in gt: countrypops, sza, gtcars, sp500, pizzaplace, and exibble. All of them are useful for experimenting with gt’s functions.

Beyond this simple example, there are many functions available in gt for creating super-customized tables.

Want to try this out? Then, take the gt Test Drive on RStudio Cloud. It’s full of ready-to-run examples.

RStudio Cloud Example

The gt package can be installed from CRAN with:

install.packages("gt")

You can also choose to install the development version of gt from GitHub:

devtools::install_github("rstudio/gt")

If you encounter a bug, have usage questions, or want to share ideas to make this package better, please feel free to file an issue.


How gt fits in with Other Packages that Generate Display Tables

The gt package joins a burgeoning collection of packages for display table generation. Why another? We feel that there is enough room in this space to innovate further. Here are some of the ways that gt contributes to this ecosystem:

  • the interface is high-level and declarative (general instructions versus very specific)
  • the formatting options are ‘batteries included’ (scientific notation, uncertainty, ranges, percentages, suffixes, localized currency, dates/times + much more)
  • there is excellent, pain-free support for footnotes
  • the output is ‘camera-ready’
  • multiple output formats are supported with the same declarative interface
  • the API closely follows tidyverse conventions by adhering to the tidyverse style guide
  • there’s a focus on making the package documentation and examples the best they can be
  • rigorous QA/QC measures: high test coverage for automated tests, and thorough manual testing by QA engineers (with every proposed code change)

While gt is trying to do something different with its own interface, it may not suit your specific needs. Here is a listing of other leading table-making R packages, with links to their respective project pages:

Code of Conduct

Please note that the gt project is released with a contributor code of conduct.
By participating in this project you agree to abide by its terms.

📄 License

gt is licensed under the MIT license. See the LICENSE.md file for more details.

© RStudio, PBC.