Generate Publication-Ready Statistical Tables

A table and summary generator: a collection of functions for generating frequency tables and cross-tabulations of categorical variables. The resulting tables can be exported to various formats (Excel, PDF, HTML, etc.) with extensive formatting and layout customization options.


tsg

CRANstatus R-CMD-check

The tsg (Table and Summary Generator) package provides functions for generating publication-ready frequency tables and cross-tabulations from data frames. Tables can be exported to Excel (XLSX), HTML, PDF, and Word (DOCX) formats with extensive styling options via a unified facade system.

Installation

install.packages("tsg")

Excel output works out of the box. The other formats need packages that are not installed with tsg; write_html(), write_pdf(), write_docx() and write_gsheet() offer to install them the first time you use them, or install them yourself:

install.packages("gt")                       # HTML
install.packages(c("gt", "webshot2"))        # PDF (plus qpdf to combine tables into one file)
install.packages(c("officer", "flextable"))  # Word
install.packages("googledrive")              # Google Sheets

Basic usage

library(tsg)

# Frequency table
generate_frequency(person_record, sex)

# Cross-tabulation
generate_crosstab(person_record, marital_status, sex)

# Summary statistics of numeric variables
generate_summary(person_record, age)

Output formats

tbl <- person_record |>
  generate_crosstab(marital_status, sex)

# Excel
write_xlsx(tbl, "table.xlsx")

# HTML
write_html(tbl, "table.html")

# PDF
write_pdf(tbl, "table.pdf")   # requires webshot2

# Word
write_docx(tbl, "table.docx")

# Google Sheets
write_gsheet(tbl, "Marital status by sex")   # requires googledrive

Styling with facades

The facade system controls table appearance uniformly across all output formats:

person_record |>
  generate_frequency(sex) |>
  add_facade(
    header.fgFill = "#003366",
    header.fontColour = "#FFFFFF",
    header.textDecoration = "bold",
    body.fontSize = 11,
    table.lastRowBold = TRUE
  ) |>
  write_xlsx("styled.xlsx")

Built-in facades are "default", "yolo", "apa", "booktabs", "striped", "gridded", "minimal", "financial", "nyt", "jama", "dark", "pastel" and "census":

write_xlsx(tbl, "booktabs.xlsx", facade = "booktabs")

More examples in the vignettes.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("tsg")

0.2.0 by Bhas Abdulsamad, 11 days ago


https://yng-me.github.io/tsg/, https://github.com/yng-me/tsg


Report a bug at https://github.com/yng-me/tsg/issues


Browse source code at https://github.com/cran/tsg


Authors: Bhas Abdulsamad [aut, cre, cph] (ORCID:


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports haven, openxlsx, fs, forcats, purrr, tidyr, glue, jsonlite, yaml, dplyr, stringr, rlang, lifecycle, stats, utils

Suggests testthat, cli, devtools, knitr, rmarkdown, tibble, webshot2, withr, DBI, dbplyr, RSQLite, googledrive, gargle, gt, officer, flextable, qpdf, chromote


Imported by mpindex.


See at CRAN