Learn R Programming

tidytlg

The goal of tidytlg is to generate table, listings, and graphs (TLG) using Tidyverse. This can be achieved multiple ways with this package.

  • Functional method: build a custom script for each TLG
  • Metadata method: build a generic script that utilizes column and table metadata to produce each TLG result

Installation

Development version

# install.packages("devtools")
devtools::install_github("pharmaverse/tidytlg")

Functional method example

library(dplyr)
library(tidytlg)

# Note cdisc_adsl is built into the package for use
ittpop <- cdisc_adsl %>%
  filter(ITTFL == "Y")

# frequency of Intend-to-Treat patients by planned treatment
tbl1 <- freq(ittpop,
             rowvar = "ITTFL",
             statlist = statlist("n"),
             colvar = "TRT01P",
             rowtext = "Analysis Set:  Intend-to-Treat Population",
             subset = ITTFL == "Y")

# N, MEAN (SD), MEDIAN, RANGE, IQ Range of age by planned treatment
tbl2 <- univar(ittpop,
               rowvar = "AGE",
               colvar = "TRT01P",
               row_header = "Age (Years)")

# frequency of Race by planned treatment
tbl3 <- freq(ittpop,
             rowvar =  "RACE",
             statlist = statlist(c("N", "n (x.x%)")),
             colvar = "TRT01P",
             row_header = "Race, n(%)")

# combine results together
tbl <- bind_table(tbl1, tbl2, tbl3)

# conver to hux object -----------------------------------------------------------------
gentlg(huxme       = tbl ,
       orientation = "landscape",
       file        = "DEMO",
       title       = "Custom Method",
       footers     = "Produced with tidytlg",
       colspan     = list(c("", "", "Xanomeline", "Xanomeline")),
       colheader   = c("", "Placebo", "High", "Low"),
       wcol        = .30)

Metadata method example

library(dplyr)
library(tidytlg)

adsl <- cdisc_adsl

table_metadata <- tibble::tribble(
  ~anbr,~func,    ~df,     ~rowvar,            ~rowtext,   ~row_header,                    ~statlist,         ~subset,
  1,   "freq", "adsl",     "ITTFL", "Analysis set: itt",            NA,                statlist("n"),  "ITTFL == 'Y'",
  2, "univar", "adsl",       "AGE",                  NA, "Age (Years)",                           NA,              NA,
  3,   "freq", "adsl",      "RACE",                  NA,  "Race, n(%)", statlist(c("N", "n (x.x%)")),              NA
) %>%
  mutate(colvar  = "TRT01PN")

tbl <- generate_results(table_metadata, 
                        column_metadata_file = system.file("extdata/column_metadata.xlsx", package = "tidytlg"),
                        tbltype = "type1") 

# conver to hux object -----------------------------------------------------------------
tblid <- "Table01"

gentlg(huxme       = tbl,
       orientation = "landscape",
       file        = tblid,
       title_file = system.file("extdata/titles.xls", package = "tidytlg"),
       wcol        = .30)

Copy Link

Version

Install

install.packages('tidytlg')

Monthly Downloads

629

Version

0.1.6

License

Apache License 2.0

Issues

Pull Requests

Stars

Forks

Maintainer

Konrad Pagacz

Last Published

May 2nd, 2025

Functions in tidytlg (0.1.6)

col_borders

Adds borders under cells in a column
insert_empty_rows

Inserts empty rows into a data frame
gentlg

Output a tidytlg table
freq

Frequency counts and percentages
generate_results

Generate Results using Table and Column Metadata
no_borders

Removes all borders from the table
tidytlg_titles

Helper functions for returning files used in gentlg
nested_freq

Generate nested count/percent for two or three levels
old_format

Adds bottom borders according to the old formatting
column_metadata

Metadata describing table column layouts
rmdpstitle

Get Titles and Footnotes for all TLGs or one specific TLG
statlist

Create a statlist interface for a table
row_border

Adds a continuous bottom border under a row
spanning_borders

Adds borders under cells in a row, excluding the first column.
replace_na_with_blank

Replace NA with ""
single_border

Adds a border under a cell
remove_zero_padding

Removes noop padding from an RTF markup
spanning_headers

Spanning headers for outputs
roundSAS

SAS rounding in R
univar

Descriptive statistics
table_metadata

Metadata describing the data, functions and arguments needed to produce your results.
tlgsetup

Setup data to support the specified column type
tidytlg

tidytlg: A package for producing tables, listings, and graphs (TLGs) using tidyverse packages.
add_indent

Add indentation variable to the results dataframe
char2factor

Convert character variable to a factor based off it's numeric variable counterpart.
add_bottom_borders

Adds bottom borders to a huxtable
add_newrows

Add the newrows variable to the results dataframe.
bind_table

Bind a set of tidytlg tables together with formatting variables
cdisc adae

ADAE data created from subsetting the CDISC ADAE dataset
add_format

Add the formatting variables of indentme, newrows, newpage, and roworder to the results dataframe
cdisc advs

ADVS data created from subsetting the CDISC ADVS dataset
cdisc adsl

ADSL data created from subsetting the CDISC ADSL with 15 subjects (5 subjects in each arm)
cdisc adlb

ADLB data created from subsetting the CDISC ADLB dataset