Generate Publication-Ready Statistical Tables

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 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")

tsg requires the following packages: gt (HTML/PDF), officer and flextable (Word). These are installed automatically. For PDF output, webshot2 is also needed:

install.packages("webshot2")  # optional, for PDF output

Basic usage

library(tsg)

# Frequency table
generate_frequency(person_record, sex)

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

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")

Styling with facades

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

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

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.1.4 by Bhas Abdulsamad, 6 months 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, gt, lifecycle, stats, utils, officer, flextable, qpdf

Suggests testthat, cli, devtools, knitr, rmarkdown, tibble, webshot2, withr


Imported by mpindex.


See at CRAN