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

565

Version

0.1.5

License

Apache License 2.0

Issues

Pull Requests

Stars

Forks

Maintainer

Konrad Pagacz

Last Published

June 15th, 2024

Functions in tidytlg (0.1.5)

no_borders

Removes all borders from the table
old_format

Adds bottom borders according to the old formatting
remove_zero_padding

Removes noop padding from an RTF markup
replace_na_with_blank

Replace NA with ""
spanning_borders

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

Spanning headers for outputs
row_border

Adds a continuous bottom border under a row
rmdpstitle

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

Adds a border under a cell
univar

Descriptive statistics
roundSAS

SAS rounding in R
tlgsetup

Setup data to support the specified column type
table_metadata

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

Create a statlist interface for a table
tidytlg

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

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

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

Adds bottom borders to a huxtable
add_indent

Add indentation variable to the results dataframe
cdisc advs

ADVS data created from subsetting the CDISC ADVS dataset
bind_table

Bind a set of tidytlg tables together with formatting variables
add_newrows

Add the newrows variable to the results dataframe.
cdisc adlb

ADLB data created from subsetting the CDISC ADLB dataset
cdisc adsl

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

Output a tidytlg table
nested_freq

Generate nested count/percent for two or three levels
insert_empty_rows

Inserts empty rows into a data frame
generate_results

Generate Results using Table and Column Metadata
col_borders

Adds borders under cells in a column
column_metadata

Metadata describing table column layouts
tidytlg_titles

Helper functions for returning files used in gentlg
freq

Frequency counts and percentages
cdisc adae

ADAE data created from subsetting the CDISC ADAE dataset