August 5, 2019

412 words 2 mins read

rstudio/gt

rstudio/gt

Easily generate information-rich, publication-quality tables from R

repo name rstudio/gt
repo link https://github.com/rstudio/gt
homepage https://gt.rstudio.com
language R
size (curr.) 87413 kB
stars (curr.) 980
created 2018-03-20
license Other

gt

lifecycle CRANstatus Travis buildstatus AppVeyor BuildStatus Coveragestatus

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 preprocessed 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 HTML output, with LaTeX and RTF planned for the future.

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 %>%
  dplyr::filter(date >= start_date & date <= end_date) %>%
  dplyr::select(-adj_close) %>%
  gt() %>%
  tab_header(
    title = "S&P 500",
    subtitle = glue::glue("{start_date} to {end_date}")
  ) %>%
  fmt_date(
    columns = vars(date),
    date_style = 3
  ) %>%
  fmt_currency(
    columns = vars(open, high, low, close),
    currency = "USD"
  ) %>%
  fmt_number(
    columns = vars(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.

You can install the development version of gt from GitHub:

remotes::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.



Code of Conduct

Please note that this project is released with a Contributor Code of Conduct.By participating in this project you agree to abide by its terms.

License

MIT © RStudio, PBC

comments powered by Disqus