Skip to content
master
Go to file
Code

Latest commit

* Add file of RTF table-building functions

* Update the `as_rtf()` function

* Modify conditional expression

* Update DESCRIPTION

* Update `context_missing_text()`

* Move `split_body_content()` to `utils_render_common.R`

* Create rtf_tests.R

* Remove unnecessary `:::` calls

* Modify use of `append()` to avoid partial-match arg

* Include correct stmts for returning an empty list()

* Transform select HTML tags to RTF code

* Include correct representation of scientific notn for RTF

* Add correct text processing for RTF

* Add RTF context code for `fmt_missing()`

* Increase widths of certain borders

* Define a plus/minus mark for RTF

* Minimize heights of table rows

* Add repeating header functionality

* Update rtf_tests.R

* Update rtf_tests.R

* Update html-13-adding_footnotes.R

* Ensure that footnote glyphs appear in more locations

* Delete ~$rquality-msrtf_2.rtf

* Use correct binding of stub col to body cols

* Update rtf_tests.R

* Add rendered RTF output

* Incorporate grand summary rows

* Update rtf_tests.R

* Update summary.rtf

* Update utils_render_rtf_redo.R

* Update rtf_tests.R

* wip: Convert Markdown to RTF via commonmark XML

* wip: Implement md text (escaping and unicode), softbreak, linebreak

* Implement md2rtf code, heading, thematic break

* Modify md2rtf strong & emph to use `{ }`

* Implement md2rtf conversion for links

* Implement md2rtf conversion for lists

* Implement md2rtf conversion for thematic break

* Make corrections to 'heading' and 'thematic break'

* Update RTF export code

At this point, RTF escaping is generally not applied (should be done in `rtf_text()`).

* Prevent double escaping RTF where necessary

* Update tests and their outputs

* Perform extra checks for title/subtitle presence

* Ensure that summary row text isn't double escaped

* Update RTF examples

* Modify characters used for missing text (RTF)

* Revert "Modify characters used for missing text (RTF)"

This reverts commit c7471a5.

* Add rtf_paste0

* Refactor RTF code

First pass of replacing `paste0()` with `rtf_paste0()`.

* Replace RTF output test files

* Improve md2rtf for 'html_inline'

* Make correction to cmark rule for lists

* Make correction to testthat test

* Update testthat tests for md2rtf conversion

* Add more md2rtf testthat tests

* Add the `block_quote` cmark rule

* Update md2rtf testthat tests

* Make several changes based on code review

* Fix remaining issue with footnotes in RTF

* Add to `globalVariables()` vector

* Update rtf_tests.R

* Create exibble.rtf

* Make changes to md2rtf paragraph and block_quote

* Update test-utils.R

* Update md.rtf

* Update test-utils.R

* Add md2rtf translation for code_block

* Update test-utils.R

* Eliminate the return of names in `text`

* Update the `md_rtf()` testing function

* Remove unnecessary RTF control words

* Modify `select()` statement

* Update utils.R

* Update test-utils.R

* Update .rtf output files

* Use `NULL` if table subtitle isn't present

* Delete utils_render_rtf.R

* Slight refactor of rtf_paste0

* Update DESCRIPTION

* Update comment

* Remove uses of `*text_list()`; reprocess examples

* Simplify stmt for obtaining `row_components`

* Refactor method for getting colors and fonts (for the header)

* Simplify `rtf_table()`

* Remove unneeded `rtf_document()` fcn

* Update `fmt_passthrough()` for RTF

* Correct `context_missing_text()`; add test

* Remove unneeded tab stops for list item.

* Make changes based on code review

* Update test-utils.R

* Remove tab stops in block_quote cmark rule

* Update test-utils.R

* Defer implementation of `block_quote`

* Update exibble.rtf

* Update test-utils.R

Co-authored-by: Joe Cheng <joe@rstudio.com>
6a791b5

Git stats

Files

Permalink
Failed to load latest commit information.

README.md

gt

Lifecycle: maturing 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 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.

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’
  • it will eventually support multiple output formats (including LaTeX) with the same declarative interface
  • the API closely follows tidyverse conventions by adhering to the tidyverse style guide
  • 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 leading table-making R packages, with links to their respective project pages:

knitr (GITHUBWEBSITE) — kableExtra (GITHUBWEBSITE) — formattable (GITHUBWEBSITE) — DT (GITHUBWEBSITE) — pander (GITHUBWEBSITE) — huxtable (GITHUBWEBSITE) — reactable (GITHUBWEBSITE) — flextable (GITHUBWEBSITE) — pixiedust (GITHUB) — tangram (GITHUB) — ztable (GITHUB) — condformat (GITHUB) — stargazer (CRAN) — xtable (CRAN)

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

You can’t perform that action at this time.