| Title: | Create TLGs using the 'tidyverse' |
| Version: | 0.11.0 |
| Language: | en-US |
| Description: | Generate tables, listings, and graphs (TLG) using 'tidyverse'. Tables can be created functionally, using a standard TLG process, or by specifying table and column metadata to create generic analysis summaries. The 'envsetup' package can also be leveraged to create environments for table creation. |
| License: | Apache License 2.0 |
| URL: | https://pharmaverse.github.io/tidytlg/main/, https://github.com/pharmaverse/tidytlg |
| BugReports: | https://github.com/pharmaverse/tidytlg/issues |
| Encoding: | UTF-8 |
| LazyData: | true |
| RoxygenNote: | 7.3.3 |
| Suggests: | testthat (≥ 2.1.0), knitr (≥ 1.23), rmarkdown (≥ 2.10), renv (≥ 0.13.2), shiny (≥ 1.3.2), kableExtra (≥ 1.3.4), haven (≥ 2.4.1), usethis (≥ 1.6.3), withr (≥ 2.3.0) |
| Imports: | cli (≥ 3.6.0), dplyr (≥ 1.1.0), tibble (≥ 2.1.3), magrittr (≥ 1.5), rlang (≥ 0.4.10), tidyr (≥ 1.0.0), stats (≥ 3.6.0), stringr (≥ 1.4.0), forcats (≥ 0.5.1), purrr (≥ 0.3.4), huxtable (≥ 5.1.0), assertthat (≥ 0.2.1), glue (≥ 1.4.2), crayon (≥ 1.4.1), methods, readxl (≥ 1.3.1), cellranger (≥ 1.1.0), png (≥ 0.1-7), ggplot2 (≥ 3.3.2), rstudioapi (≥ 0.13) |
| Depends: | R (≥ 4.1.0) |
| VignetteBuilder: | knitr |
| Config/testthat/edition: | 3 |
| NeedsCompilation: | no |
| Packaged: | 2025-12-19 07:23:49 UTC; kpagacz |
| Author: | Nicholas Masel [aut],
Steven Haesendonckx [aut],
Pelagia Alexandra Papadopoulou [aut],
Sheng-Wei Wang [aut],
Eli Miller |
| Maintainer: | Konrad Pagacz <kpagacz@its.jnj.com> |
| Repository: | CRAN |
| Date/Publication: | 2025-12-19 08:00:02 UTC |
tidytlg: A package for producing tables, listings,
and graphs (TLGs) using tidyverse packages.
Description
The tidytlg package provide a set of function allowing you to produce TLGs
using table metadata.
tidytlg Options
tidytlg.row_type.levels- The values of row_type and their respective levels. Default: c("TABLE_BY_HEADER", "BY_HEADER1", "BY_HEADER2", "BY_HEADER3", "BY_HEADER4", "BY_HEADER5", "HEADER", "N", "VALUE", "NESTED")tidytlg.fontsize.title- Font size for titles in points. Default: 10tidytlg.fontsize.table.footnote- Font size for footnotes in points. For tables. Default: 9tidytlg.fontsize.listing.footnote- Font size for footnotes in points. For listings. Default: 8tidytlg.fontsize.graph.footnote- Font size for footnotes in points. For graphs. Default: 8tidytlg.fontsize.table- Font size for tables in points. Default: 9tidytlg.fontsize.graph- Font size for graphs in points. Default: 10tidytlg.fontsize.listing- Font size for listings in points. Default: 8tidytlg.right.padding- Amount of right padding for cells in points. Default: 1tidytlg.left.padding- Amount of left padding for cells in points. Default: 1tidytlg.stat_labels- Labels to be used for each summary statistic in the output table. Will need to have all available statistics if this option is changed!tidytlg.precision.extra- Value to be added on for each summary statistic when calculating precision. This will be used to make different statistics have different precision as neededtidytlg.nested_freq.statlist.default- Defaultstatlistobject for nested_freq tables. Default:statlist("n (x.x)")tidytlg.univar.statlist.default- Defaultstatlistobject forunivartables. Default:statlist(c("N", "MEANSD", "MEDIAN", "RANGE", "IQRANGE"))tidytlg.freq.statlist.default- Defaultstatlistobject for frequency tables. Default:statlist("n (x.x)")tidytlg.stat_labels- Adata.framecontrolling how the stats are labeled in aunivartable. See 'Default Stat Labels' section for defaults.tidytlg.denoms.message- Aboolean, should a message print detailing what the denominators are?
Default Stat Labels
| stat | label |
N | N |
SUM | Sum |
MEAN | Mean |
GeoMEAN | Geometric Mean |
SD | Std. Deviation |
SE | Std. Error |
GSD | Geometric Std. Deviation |
GSE | Geometric Std. Error |
CV | CV |
MEANSD | Mean (SD) |
MEANSE | Mean (SE) |
MEDIAN | Median |
MIN | Minimum |
MAX | Maximum |
RANGE | Range |
Q1 | First quartile |
Q3 | Third quartile |
IQRANGE | IQ range |
MEDRANGE | Median (Range) |
MEDIQRANGE | Median (Q1; Q3) |
MEAN_CI | Mean (95% C.I.) |
GeoMEAN_CI | Geometric Mean (95% C.I.) |
Default Precision Extra
| stat | extra |
N | 0 |
SUM | 0 |
MEAN | 1 |
GeoMEAN | 1 |
SD | 2 |
SE | 2 |
GSD | 2 |
GSE | 2 |
CV | 1 |
MEDIAN | 1 |
MIN | 0 |
MAX | 0 |
Q1 | 1 |
Q3 | 1 |
LCL_MEAN | 2 |
UCL_MEAN | 2 |
LCL_GeoMEAN | 2 |
UCL_GeoMEAN | 2 |
Updating Options
For a single session, an option can be changed by
option(<optionToChange> = <NewValue>)To change an option for a single projects across sessions in that projects, place the options update in the
.Rprofilein that project directory.To change an option for a user across all sessions, place the options update in the
.Rprofilefile in the users home directory.To change an option for all users in an R environment, place the options update in the
.Rprofile.sitefile in the R home directory.
Author(s)
Maintainer: Konrad Pagacz kpagacz@its.jnj.com
Authors:
Nicholas Masel nmasel@its.jnj.com
Steven Haesendonckx shaesen2@its.jnj.com
Pelagia Alexandra Papadopoulou ppapadop@its.jnj.com
Sheng-Wei Wang swang69@its.jnj.com
Eli Miller eli.miller@atorusresearch.com (ORCID)
Nathan Kosiba nkosiba@its.jnj.com (ORCID)
Aidan Ceney aceney@its.jnj.com (ORCID)
Other contributors:
Janssen R&D [copyright holder, funder]
David Hugh-Jones (Author of included 'huxtable' library) [copyright holder]
See Also
Useful links:
Report bugs at https://github.com/pharmaverse/tidytlg/issues
Adds bottom borders to a huxtable
Description
Adds bottom borders to a huxtable
Usage
add_bottom_borders(ht, border_matrix = no_borders(ht), transform_fns = list())
Arguments
ht |
|
border_matrix |
(optional) |
transform_fns |
(optional)
The functions in the list are applied sequentially to |
Details
Adds bottom borders to a huxtable based on
a matrix indicating where the borders should be put.
This function is responsible for adding bottom borders to a huxtable object.
It supports borders spanning multiple columns and borders that are under neighbouring,
single cells (or merged cells), but separate (see examples).
This feature has limitations. Mainly, it does not support both versions of the borders (continuous and separate) on the same line. In such a case, the borders in the resulting RTF look misaligned.
Value
A huxtable with added borders.
border_matrix details
You mark where the bottom borders should go in the table by passing a matrix.
The matrix has to have the same number of columns as the passed huxtable
and the number of rows lower by one than the passed huxtable. Each cell
in border_matrix corresponds to a cell in huxtable (starting from the first row).
Internally, the function adds the first row of 0s to border_matrix before the execution.
At that point, border_matrix's dimensions match ht's dimensions.
Table:
| foo | bar |
baz | bim
|
A border matrix:
| 1 | 1 |
| 0 | 0 |
The above border matrix puts a bottom border across the entire first row and no borders in the second row.
A border matrix:
| 1 | 2 |
| 0 | 0 |
The above border matrix puts one border under the first cell in the first row; and another border (separate from the first one) under the second cell in the first row. The second row stays without any borders.
Functions transforming the border matrix
The below functions can be passed to gentlg()'s
border_fns argument to modify how gentlg renders
the borders under the cells.
Border functions:
border_fns will accept your own, custom functions as long as
they adhere to the format.
All the functions passed to border_fns need to accept two arguments:
the first - the printed
huxtableobject,the second - a border matrix.
They also must return a matrix interpreted the same way as border_matrix
passed to add_bottom_borders or gentlg().
Examples
border_matrix <- matrix(c(1, 1, 2, 0, 1, 1, 0, 0, 0), nrow = 3, ncol = 3)
ht <- huxtable::as_huxtable(
data.frame(a = c(1, 2, 3), b = c("a", "b", "c"), c = c(TRUE, FALSE, TRUE))
)
# By default adds no borders
add_bottom_borders(ht, border_matrix)
# Adds spanning borders under cells with text in the second row
add_bottom_borders(ht, transform_fns = list(spanning_borders(2)))
# Adds spanning borders under cells with text in the second row and a border
# under a cell in row 3 and column 3
add_bottom_borders(ht, transform_fns = list(spanning_borders(2), single_border(3, 3)))
final <- data.frame(
label = c(
"Overall", "Safety Analysis Set",
"Any Adverse event{\\super a}", "- Serious Adverse Event"
),
Drug_A = c("", "40", "10 (25%)", "0"),
Drug_B = c("", "40", "10 (25%)", "0"),
anbr = c(1, 2, 3, 4),
roworder = c(1, 1, 1, 1),
boldme = c(1, 0, 0, 0),
newrows = c(0, 0, 1, 0),
indentme = c(0, 0, 0, 1),
newpage = c(0, 0, 0, 0)
)
# Add spanning bottom borders under the cells in the first row
gentlg(
huxme = final,
wcol = c(0.70, 0.15, 0.15),
file = "TSFAEX",
colheader = c("", "Drug A", "Drug B"),
title = "This is Amazing Demonstration 1",
footers = c(
"Note: For demonstrative purposes only",
"{\\super a} Subjects are counted once for any given event."
),
border_fns = list(no_borders, spanning_borders(1))
)
# Tables with no bottom borders
gentlg(
huxme = final,
wcol = c(0.70, 0.15, 0.15),
file = "TSFAEX",
colheader = c("", "Drug A", "Drug B"),
title = "This is Amazing Demonstration 1",
footers = c(
"Note: For demonstrative purposes only",
"{\\super a} Subjects are counted once for any given event."
),
border_fns = list(no_borders)
)
# Tables with a border under cell in the 3nd row and 3rd column,
# and borders under cells in the first row
gentlg(
huxme = final,
wcol = c(0.70, 0.15, 0.15),
file = "TSFAEX",
colheader = c("", "Drug A", "Drug B"),
title = "This is Amazing Demonstration 1",
footers = c(
"Note: For demonstrative purposes only",
"{\\super a} Subjects are counted once for any given event."
),
border_fns = list(no_borders, spanning_borders(1), single_border(3, 3))
)
# We discourage, but you can pass the border matrix directly
mat <- matrix(rep(0, 8 * 3), ncol = 3, nrow = 8)
mat[3, 3] <- 1
gentlg(
huxme = final,
wcol = c(0.70, 0.15, 0.15),
file = "TSFAEX",
colheader = c("", "Drug A", "Drug B"),
title = "This is Amazing Demonstration 1",
footers = c(
"Note: For demonstrative purposes only",
"{\\super a} Subjects are counted once for any given event."
),
bottom_borders = mat, # The same as a single border under 3nd row and 3rd column
border_fns = list()
)
# clean up.
file.remove("tsfaex.rtf")
Add the formatting variables of indentme, newrows, newpage, and roworder to
the results dataframe
Description
Add the formatting variables of indentme, newrows, newpage, and roworder to
the results dataframe
Usage
add_format(df, tableby = NULL, groupby = NULL, .keep = FALSE)
Arguments
df |
(required) dataframe of results and must contain the |
tableby |
(optional) character vector containing table by variables. |
groupby |
(optional) character vector containing group by variables. |
.keep |
(optional) should |
Value
dataframe with the formatting variables indentme, newrows, newpage, and roworder added.
Examples
df <- tibble::tibble(
row_type =
c(
"TABLE_BY_HEADER", "HEADER", "BY_HEADER1", "N", "VALUE",
"COUNTS", "UNIVAR", "NESTED", "NESTED"
),
nested_level = c(NA, NA, NA, NA, NA, NA, NA, 1, 2),
group_level = c(0, 0, 0, 0, 0, 0, 0, 0, 0),
label = c(NA, NA, NA, NA, NA, "N", NA, NA, NA),
by = c(NA, NA, NA, NA, NA, NA, NA, NA, NA),
tableby = c(NA, NA, NA, NA, NA, NA, NA, NA, NA),
anbr = c(1:9)
)
add_format(df)
Add indentation variable to the results dataframe
Description
Add the indentme variable to your results data. This drives the number of
indents for the row label text (e.g. 0, 1, 2, etc.).
Usage
add_indent(df)
Arguments
df |
dataframe of results that contains |
Details
The group_level variable, which is added to the results dataframe by freq()
and univar() calls, is needed to define indentation when by variables are
used for summary.
The nested_level variable, which is added to the results dataframe by
nested_freq(), is needed to define indentation for each level of nesting.
Both of these are added to the default indentation which is driven by
row_type.
| row_type | default indentation |
| TABLE_BY_HEADER | 0 |
| BY_HEADER[1-9] | 0 |
| HEADER | 0 |
| N | 1 |
| VALUE | 2 |
| NESTED | 0 |
Value
dataframe with the indentme variable added.
Examples
df <- tibble::tibble(
row_type = c(
"TABLE_BY_HEADER", "HEADER",
"BY_HEADER1", "N", "VALUE", "COUNTS", "UNIVAR", "NESTED", "NESTED"
),
nested_level = c(NA, NA, NA, NA, NA, NA, NA, 1, 2),
group_level = c(0, 0, 0, 0, 0, 0, 0, 0, 0),
label = c(NA, NA, NA, NA, NA, "N", NA, NA, NA),
by = c(NA, NA, NA, NA, NA, NA, NA, NA, NA),
tableby = c(NA, NA, NA, NA, NA, NA, NA, NA, NA)
)
add_indent(df)
Add the newrows variable to the results dataframe.
Description
The newrows variable is used by gentlg() to define when to add a blank row
to the output. Data will be grouped by anbr and the variables passed into
the tableby and groupby parameters. newrows will be set to 1
for the first record in each group, except for the first row in the data.
The first row will always be set to 0.
Usage
add_newrows(df, tableby = NULL, groupby = NULL)
Arguments
df |
dataframe of results. must contain the |
tableby |
character vector containing table by variables used to generate the results. |
groupby |
character vector containing group by variables used to generate the results. |
Value
dataframe with the variable newrows and roworder added.
newrows is used by gentlg to insert line breaks.
Examples
# Example showing how newrows is set to one for each new anbr except
# the first
tbl <-
structure(
list(
rowvar = c("RANDFL", "AGE", "AGE", "AGE", "AGE", "AGE"),
anbr = c(1L, 2L, 2L, 2L, 2L, 2L),
label = c(
"Analysis set: Subjects Randomized", "Age (Years)", "N",
"Mean (SD)", "Range", "IQ Range"
),
row_type = c("COUNT", "UNIVAR", "UNIVAR", "UNIVAR", "UNIVAR", "UNIVAR")
),
row.names = c(NA, -6L),
class = c("tbl_df", "tbl", "data.frame")
)
add_newrows(tbl)
# Example of use when you have results summarized by one or more variables
tbl2 <- tibble::tribble(
~anbr, ~SEX, ~label, ~row_type,
"01", "F", "Sex : F", "TABLE_BY_HEADER",
"01", "F", "<65", "VALUE",
"01", "F", "65-80", "VALUE",
"01", "F", ">80", "VALUE",
"01", "M", "Sex : M", "TABLE_BY_HEADER",
"01", "M", "<65", "VALUE",
"01", "M", "65-80", "VALUE",
"01", "M", ">80", "VALUE"
)
add_newrows(tbl2, tableby = "SEX")
tbl3 <- tibble::tribble(
~anbr, ~SEX, ~ETHNIC, ~label, ~row_type,
"01", "F", NA, "Sex : F", "TABLE_BY_HEADER",
"01", "F", "HISPANIC OR LATINO", "HISPANIC OR LATINO", "BY_HEADER1",
"01", "F", "HISPANIC OR LATINO", "<65", "VALUE",
"01", "F", "HISPANIC OR LATINO", ">80", "VALUE",
"01", "F", "HISPANIC OR LATINO", "65-80", "VALUE",
"01", "F", "NOT HISPANIC OR LATINO", "NOT HISPANIC OR LATINO", "BY_HEADER1",
"01", "F", "NOT HISPANIC OR LATINO", "<65", "VALUE",
"01", "F", "NOT HISPANIC OR LATINO", "65-80", "VALUE",
"01", "F", "NOT HISPANIC OR LATINO", ">80", "VALUE",
"01", "M", NA, "Sex : M", "TABLE_BY_HEADER",
"01", "M", "HISPANIC OR LATINO", "HISPANIC OR LATINO", "BY_HEADER1",
"01", "M", "HISPANIC OR LATINO", "<65", "VALUE",
"01", "M", "HISPANIC OR LATINO", "65-80", "VALUE",
"01", "M", "HISPANIC OR LATINO", ">80", "VALUE",
"01", "M", "NOT HISPANIC OR LATINO", "NOT HISPANIC OR LATINO", "BY_HEADER1",
"01", "M", "NOT HISPANIC OR LATINO", "<65", "VALUE",
"01", "M", "NOT HISPANIC OR LATINO", "65-80", "VALUE",
"01", "M", "NOT HISPANIC OR LATINO", ">80", "VALUE"
)
add_newrows(tbl3, tableby = "SEX", groupby = "ETHNIC")
Bind a set of tidytlg tables together with formatting variables
Description
bind_table combines analysis results with formatting variables
(indentme, newrows, newpage) based on by variables
(tablebyvar, rowbyvar), such that appropriate formatting (indentation,
line break, page break) can be applied while creating the output.
It can also attach the column metadata attribute,
which will be automatically used in gentlg for creating output.
Usage
bind_table(
...,
colvar = NULL,
tablebyvar = NULL,
rowbyvar = NULL,
prefix = NULL,
add_count = FALSE,
add_format = TRUE,
column_metadata_file = NULL,
column_metadata = NULL,
tbltype = NULL
)
Arguments
... |
(required) a set of |
colvar |
(required) treatment variable within |
tablebyvar |
(optional) repeat entire table by variable within |
rowbyvar |
(optional) any |
prefix |
(optional) text to prefix the values of |
add_count |
(optional) Should a count be included in the |
add_format |
(optional) Should format be added to the output table?
This is done using the |
column_metadata_file |
(optional) An excel file for |
column_metadata |
(optional) A dataframe containing the column metadata.
This will be used in place of |
tbltype |
(optional) A value used to subset the |
Value
The tidytlg tables bound together reflecting the
tablebyvars used.
Examples
library(magrittr)
# bind tables together
t1 <- cdisc_adsl %>%
freq(
colvar = "TRT01PN",
rowvar = "ITTFL",
statlist = statlist("n"),
subset = ITTFL == "Y",
rowtext = "Analysis set: ITT"
)
t2 <- cdisc_adsl %>%
univar(
colvar = "TRT01PN",
rowvar = "AGE",
decimal = 0,
row_header = "Age, years"
)
bind_table(t1, t2)
# bind tables together w/by groups
t1 <- cdisc_adsl %>%
freq(
colvar = "TRT01PN",
rowvar = "ITTFL",
rowbyvar = "SEX",
statlist = statlist("n"),
subset = ITTFL == "Y",
rowtext = "Analysis set: ITT"
)
t2 <- cdisc_adsl %>%
univar(
colvar = "TRT01PN",
rowvar = "AGE",
rowbyvar = "SEX",
decimal = 0,
row_header = "Age, years"
)
bind_table(t1, t2, rowbyvar = "SEX")
# bind tables together w/table by groups
t1 <- cdisc_adsl %>%
freq(
colvar = "TRT01PN",
rowvar = "ITTFL",
tablebyvar = "SEX",
statlist = statlist("n"),
subset = ITTFL == "Y",
rowtext = "Analysis set: ITT"
)
t2 <- cdisc_adsl %>%
univar(
colvar = "TRT01PN",
rowvar = "AGE",
tablebyvar = "SEX",
decimal = 0,
row_header = "Age, years"
)
bind_table(t1, t2, tablebyvar = "SEX")
# w/prefix
bind_table(t1, t2, tablebyvar = "SEX", prefix = "Gender: ")
# w/counts
bind_table(t1, t2, tablebyvar = "SEX", add_count = TRUE, colvar = "TRT01PN")
ADAE data created from subsetting the CDISC ADAE dataset
Description
ADAE data created from subsetting the CDISC ADAE dataset
Usage
cdisc_adae
Format
A data frame with 84 rows and 55 variables:
STUDYIDStudy Identifier
SITEIDStudy Site Identifier
USUBJIDUnique Subject Identifier
SUBJIDSubject Identifier for the Study
TRTAActual Treatment
TRTANActual Treatment (N)
AGEAge
AGEGR1Pooled Age Group 1
AGEGR1NPooled Age Group 1 (N)
RACERace
RACENRace (N)
SEXSex
SAFFLSafety Population Flag
TRTSDTDate of First Exposure to Treatment
TRTEDTDate of Last Exposure to Treatment
ASTDTAnalysis Start Date
ASTDTFAnalysis Start Date Imputation Flag
ASTDYAnalysis Start Relative Day
AENDTAnalysis End Date
AENDYAnalysis End Relative Day
ADURNAEDuration (N)ADURUAEDuration UnitsAETERMReported Term for the Adverse Event
AELLTLowest Level Term
AELLTCDLowest Level Term Code
AEDECODDictionary-Derived Term
AEPTCDPreferred Term Code
AEHLTHigh Level Term
AEHLTCDHigh Level Term Code
AEHLGTHigh Level Group Term
AEHLGTCDHigh Level Group Term Code
AEBODSYSBody System or Organ Class
AESOCPrimary System Organ Class
AESOCCDPrimary System Organ Class Code
AESEVSeverity/Intensity
AESERSerious Event
AESCANInvolves Cancer
AESCONGCongenital Anomaly or Birth Defect
AESDISABPersist or
SignifDisability/IncapacityAESDTHResults in Death
AESHOSPRequires or Prolongs Hospitalization
AESLIFEIs Life Threatening
AESODOccurred with Overdose
AERELCausality
AEACNAction Taken with Study Treatment
AEOUTOutcome of Adverse Event
AESEQSequence Number
TRTEMFLTreatment Emergent Analysis Flag
AOCCFLFirst Occurrence of Any
AEFlagAOCCSFLFirst Occurrence of
SOCFlagAOCCPFLFirst Occurrence of Preferred Term Flag
AOCC02FLFirst Occurrence 02 Flag for Serious
AOCC03FLFirst Occurrence 03 Flag for Serious
SOCAOCC04FLFirst Occurrence 04 Flag for Serious
PTCQ01NAMCustomized Query 01 Name
AOCC01FLFirst Occurrence 01 Flag for
CQ01
Source
CDISC SDTM/ADAM Pilot Project.
ADLB data created from subsetting the CDISC ADLB dataset
Description
ADLB data created from subsetting the CDISC ADLB dataset
Usage
cdisc_adlb
Format
A data frame with 2154 rows and 46 variables:
STUDYIDStudy Identifier
SUBJIDSubject Identifier for the Study
USUBJIDUnique Subject Identifier
TRTAActual Treatment
TRTANActual Treatment (N)
TRTSDTDate of First Exposure to Treatment
TRTEDTDate of Last Exposure to Treatment
AGEAge
AGEGR1Pooled Age Group 1
AGEGR1NPooled Age Group 1 (N)
RACERace
RACENRace (N)
SEXSex
COMP24FLFinishers of Week 24 Population Flag
DSRAEFLDiscontinued due to
AE?SAFFLSafety Population Flag
AVISITAnalysis Visit
AVISITNAnalysis Visit (N)
ADYAnalysis Relative Day
ADTAnalysis Date
VISITVisit Name
VISITNUMVisit Number
PARAMParameter
PARAMCDParameter Code
PARAMNParameter (N)
PARCAT1Parameter Category 1
AVALAnalysis Value
BASEBaseline Value
CHGChange from Baseline
A1LOAnalysis Range 1 Lower Limit
A1HIAnalysis Range 1 Upper Limit
R2A1LORatio to Analysis Range 1 Lower Limit
R2A1HIRatio to Analysis Range 1 Upper Limit
BR2A1LOBase Ratio to Analysis Range 1 Lower Limit
BR2A1HIBase Ratio to Analysis Range 1 Upper Limit
ANL01FLAnalysis 01 - Special Interest Flag
ALBTRVALAmount Threshold Range
ANRINDAnalysis Reference Range Indicator
BNRINDBaseline Reference Range Indicator
ABLFLBaseline Record Flag
AENTMTFLLast value in treatment visit
LBSEQSequence Number
LBNRINDReference Range Indicator
LBSTRESNNumeric Result/Finding in Standard Units
Source
CDISC SDTM/ADAM Pilot Project.
ADSL data created from subsetting the CDISC ADSL with 15 subjects (5 subjects in each arm)
Description
ADSL data created from subsetting the CDISC ADSL with 15 subjects (5 subjects in each arm)
Usage
cdisc_adsl
Format
A data frame with 15 rows and 49 variables:
STUDYIDStudy Identifier
USUBJIDUnique Subject Identifier
SUBJIDSubject Identifier for the Study
SITEIDStudy Site Identifier
SITEGR1Pooled Site Group 1
ARMDescription of Planned Arm
TRT01PPlanned Treatment for Period 01
TRT01PNPlanned Treatment for Period 01 (N)
TRT01AActual Treatment for Period 01
TRT01ANActual Treatment for Period 01 (N)
TRTSDTDate of First Exposure to Treatment
TRTEDTDate of Last Exposure to Treatment
TRTDURDuration of Treatment (days)
AVGDDAvg Daily Dose (as planned)
CUMDOSECumulative Dose (as planned)
AGEAge
AGEGR1Pooled Age Group 1
AGEGR1NPooled Age Group 1 (N)
AGEUAge Units
RACERace
RACENRace (N)
SEXSex
ETHNICEthnicity
SAFFLSafety Population Flag
ITTFLIntent-To-Treat Population Flag
EFFFLEfficacy Population Flag
COMP8FLFinishers of Week 8 Population Flag
COMP16FLFinishers of Week 16 Population Flag
COMP24FLFinishers of Week 24 Population Flag
DISCONFLDid the Subject Discontinue the Study?
DSRAEFLDiscontinued due to
AE?DTHFLSubject Died?
BMIBLBaseline BMI (kg/m^2)
BMIBLGR1Pooled Baseline BMI Group 1
HEIGHTBLBaseline Height (cm)
WEIGHTBLBaseline Weight (kg)
EDUCLVLYears of Education
DISONSDTDate of Onset of Disease
DURDISDuration of Disease (Months)
DURDSGR1Pooled Disease Duration Group 1
VISIT1DTDate of Visit 1
RFSTDTCSubject Reference Start Date/Time
RFENDTCSubject Reference End Date/Time
VISNUMENEnd of Treatment Visit (Visit 12 or Early Term.)
RFENDTDate of Discontinuation/Completion
DCDECODStandardized Disposition Term
EOSSTTEnd of Study Status
DCREASCDReason for Discontinuation
MMSETOTMMSETotal
Source
CDISC SDTM/ADAM Pilot Project.
ADVS data created from subsetting the CDISC ADVS dataset
Description
ADVS data created from subsetting the CDISC ADVS dataset
Usage
cdisc_advs
Format
A data frame with 1938 rows and 35 variables:
STUDYIDStudy Identifier
SITEIDStudy Site Identifier
USUBJIDUnique Subject Identifier
AGEAge
AGEGR1Pooled Age Group 1
AGEGR1NPooled Age Group 1 (N)
RACERace
RACENRace (N)
SEXSex
SAFFLSafety Population Flag
TRTSDTDate of First Exposure to Treatment
TRTEDTDate of Last Exposure to Treatment
TRTPPlanned Treatment
TRTPNPlanned Treatment (N)
TRTAActual Treatment
TRTANActual Treatment (N)
PARAMCDParameter Code
PARAMParameter
PARAMNParameter (N)
ADTAnalysis Date
ADYAnalysis Relative Day
ATPTNAnalysis Timepoint (N)
ATPTAnalysis Timepoint
AVISITAnalysis Visit
AVISITNAnalysis Visit (N)
AVALAnalysis Value
BASEBaseline Value
BASETYPEBaseline Value
CHGChange from Baseline
PCHGPercent Change from Baseline
VISITNUMVisit Number
VISITVisit Name
VSSEQSequence Number
ANL01FLAnalysis 01 - Special Interest Flag
ABLFLBaseline Record Flag
Source
CDISC SDTM/ADAM Pilot Project.
Convert character variable to a factor based off it's numeric variable counterpart.
Description
Convert character variable to a factor based off it's numeric variable counterpart.
Usage
char2factor(df, c_var, n_var)
Arguments
df |
data frame. |
c_var |
character variable within the data frame. |
n_var |
numeric variable counter part within the data frame to control the levels. |
Value
A factor.
Examples
df <- tibble::tribble(
~TRT01P, ~TRT01PN,
"Placebo", 1,
"Low Dose", 2,
"High Dose", 3
)
# alphabetical order
dplyr::arrange(df, TRT01P)
# change to factor with char2factor
df$TRT01P <- char2factor(df, "TRT01P", "TRT01PN")
# factor order
dplyr::arrange(df, TRT01P)
Adds borders under cells in a column
Description
Adds borders under cells in a column
Usage
col_borders(col, rows)
Arguments
col |
|
rows |
|
See Also
Other border_functions:
no_borders(),
row_border(),
single_border(),
spanning_borders()
Metadata describing table column layouts
Description
This is used by tlgsetup to prepare you input data to support
the desired column layout.
Usage
column_metadata
Format
A data frame with one row per column for each table type and six variables:
tbltypeidentifier used to group a table column layout
coldefdistinct variable values used, typically numeric and typically a treatment or main effect variable, think
TRT01PNdecodedecode of
coldefthat will display as a column header in the tablespan1spanning header to display across multiple columns
span2spanning header to display across multiple columns, second level
span3spanning header to display across multiple columns, third level
Frequency counts and percentages
Description
Frequency counts and percentages for a variable by treatment and/or group.
Usage
freq(
df,
denom_df = df,
colvar = NULL,
tablebyvar = NULL,
rowvar = NULL,
rowbyvar = NULL,
statlist = getOption("tidytlg.freq.statlist.default"),
decimal = 1,
nested = FALSE,
cutoff = NULL,
cutoff_stat = "pct",
subset = TRUE,
descending_by = NULL,
display_missing = FALSE,
rowtext = NULL,
row_header = NULL,
.keep = TRUE,
.ord = FALSE,
pad = TRUE,
...
)
Arguments
df |
(required) dataframe containing records to summarize by treatment. |
denom_df |
(optional) dataframe used for population based denominators
(default = |
colvar |
(required) treatment variable within |
tablebyvar |
(optional) repeat entire table by variable within |
rowvar |
(required) character vector of variables to summarize within the dataframe. |
rowbyvar |
(optional) repeat |
statlist |
(optional) |
decimal |
(optional) decimal precision root level default (default = 1). |
nested |
(optional) INTERNAL USE ONLY. The default should
not be changed. Switch on when this function is called by
|
cutoff |
(optional) percentage cutoff threshold. This can be passed as a
numeric cutoff, in that case any rows with greater than or equal to that
cutoff will be preserved, others will be dropped. To specify a single column
to define the cutoff logic, pass a character value of the form
|
cutoff_stat |
(optional) The value to cutoff by, |
subset |
(optional) An R expression that will be passed to a
|
descending_by |
(optional) The column or columns to sort descending
counts. Can also provide a named list to do ascending order ex.
|
display_missing |
(optional) Should the "missing" values be displayed?
If missing values are displayed, denominators will include missing values.
(default = |
rowtext |
(optional) A character vector used to rename the |
row_header |
(optional) A character vector to be added to the table. |
.keep |
(optional) Should the |
.ord |
Should the ordering columns be output with the table? This is useful if a table needs to be merged or reordered in any way after build. |
pad |
(optional) A boolean that controls if levels with zero records
should be included in the final table. (default = |
... |
(optional) Named arguments to be included as columns on the table. |
Value
A dataframe of results
Sorting a 'freq' table
By default, a frequency table is sorted based on the factor level of the
rowvar variable. If the rowvar variable isn't a factor, it will be
sorted alphabetically. This behavior can be modified in two ways, the first
is the char2factor() function that offers a interface for discretization a
variable based on a numeric variable, like VISITN. The second is based on
the descending_by argument which will sort based on counts on a variable.
Examples
adsl <- data.frame(
USUBJID = c("DEMO-101", "DEMO-102", "DEMO-103"),
RACE = c("WHITE", "BLACK", "ASIAN"),
SEX = c("F", "M", "F"),
colnbr = factor(c("Placebo", "Low", "High"))
)
# Unique subject count of a single variable
freq(adsl,
colvar = "colnbr",
rowvar = "RACE",
statlist = statlist("n")
)
# Unique subject count and percent of a single variable
freq(adsl,
colvar = "colnbr",
rowvar = "RACE",
statlist = statlist(c("N", "n (x.x%)"))
)
# Unique subject count of a variable by another variable
freq(adsl,
colvar = "colnbr",
rowvar = "RACE",
rowbyvar = "SEX",
statlist = statlist("n")
)
# Unique subject count of a variable by another variable using colvar and
# group to define the denominator
freq(adsl,
colvar = "colnbr",
rowvar = "RACE",
rowbyvar = "SEX",
statlist = statlist("n (x.x%)", denoms_by = c("colnbr", "SEX"))
)
# Cut records where count meets threshold for any column
freq(cdisc_adsl,
rowvar = "ETHNIC",
colvar = "TRT01P",
statlist = statlist("n (x.x%)"),
cutoff = "5",
cutoff_stat = "n"
)
# Cut records where count meets threshold for a specific column
freq(cdisc_adsl,
rowvar = "ETHNIC",
colvar = "TRT01P",
statlist = statlist("n (x.x%)"),
cutoff = "Placebo >= 3",
cutoff_stat = "n"
)
# Below illustrates how to make the same calls to freq() as above, using
# table and column metadata.
# Unique subject count of a single variable
table_metadata <- tibble::tribble(
~anbr, ~func, ~df, ~rowvar, ~statlist, ~colvar,
1, "freq", "cdisc_adsl", "ETHNIC", statlist("n"), "TRT01PN"
)
generate_results(table_metadata,
column_metadata = column_metadata,
tbltype = "type1"
)
# Unique subject count and percent of a single variable
table_metadata <- tibble::tribble(
~anbr, ~func, ~df, ~rowvar, ~statlist, ~colvar,
"1", "freq", "cdisc_adsl", "ETHNIC", statlist(c("N", "n (x.x%)")), "TRT01PN"
)
generate_results(table_metadata,
column_metadata = column_metadata,
tbltype = "type1"
)
# Cut records where count meets threshold for any column
table_metadata <- tibble::tibble(
anbr = "1", func = "freq", df = "cdisc_adsl", rowvar = "ETHNIC",
statlist = statlist("n (x.x%)"), colvar = "TRT01PN", cutoff = 5,
cutoff_stat = "n"
)
generate_results(table_metadata,
column_metadata = column_metadata,
tbltype = "type1"
)
# Cut records where count meets threshold for a specific column
table_metadata <- tibble::tibble(
anbr = 1, func = "freq", df = "cdisc_adsl", rowvar = "ETHNIC",
statlist = statlist("n (x.x%)"), colvar = "TRT01PN",
cutoff = "col1 >= 3", cutoff_stat = "n"
)
generate_results(table_metadata,
column_metadata = column_metadata,
tbltype = "type1"
)
Generate Results using Table and Column Metadata
Description
Generate Results using Table and Column Metadata
Usage
generate_results(
table_metadata,
column_metadata_file = NULL,
column_metadata = NULL,
env = parent.frame(),
tbltype = NULL,
add_count = FALSE
)
Arguments
table_metadata |
a data frame containing table metadata (see ?table_metadata for details) |
column_metadata_file |
An excel file with the data
for |
column_metadata |
A data frame containing the column metadata. This will
be used in place of |
env |
environment to find data frame specified in the table metadata (defaults to parent environment). |
tbltype |
If used, this will be used to subset
the |
add_count |
Passed to |
Value
dataframe of results
Output a tidytlg table
Description
Generate and output a huxtable with desired properties
During this function call, the huxtable can be written to an RTF or
displayed in HTML. gentlg is vectorized, see parameter descriptions
to learn for which arguments.
Usage
gentlg(
huxme = NULL,
tlf = "Table",
format = "rtf",
colspan = NULL,
idvars = NULL,
plotnames = NULL,
plotwidth = NULL,
plotheight = NULL,
wcol = 0.45,
orientation = "portrait",
opath = ".",
title_file = NULL,
file = NULL,
title = NULL,
footers = NULL,
print.hux = TRUE,
watermark = NULL,
colheader = NULL,
pagenum = FALSE,
bottom_borders = "old_format",
border_fns = list(),
alignments = list()
)
Arguments
huxme |
(optional) For tables and listings, A list of input dataframes
containing all columns of interest. For graphs, either |
tlf |
(optional) String, representing the output choice. Choices are
|
format |
(optional) String, representing the output format. Choices are
|
colspan |
(optional) A list of character vectors representing the spanning headers to be used for the table or listing. The first vector represents the top spanning header, etc. Each vector should have a length equal to the number of columns in the output data frame. A spanning header is identified through the use of the same column name in adjacent elements. Vectorized. |
idvars |
(optional) Character vector defining the columns of a listing
where repeated values should be removed recursively. If |
plotnames |
(optional) Character vector containing the names of the PNG
files, with their extension to be incorporated for figure outputs.
The PNG files need to be located in the path defined by the
parameter |
plotwidth |
(optional) Numerical value that indicates the plot width in cm for figure outputs. (Default = 6) |
plotheight |
(optional) Numerical value that indicates the plot height in cm for figure outputs. (Default = 5) |
wcol |
(optional) Can be a single numerical value that represents the
width of the first column or a vector, specifying the lengths of all columns
in the final table or listing. |
orientation |
(optional) String: "portrait" or "landscape". (Default = "portrait") |
opath |
(optional) File path pointing to the output files (including PNG files for graphs). (Default = "."). |
title_file |
An Excel file that will be read in
with |
file |
(required) String. Output identifier.
File name will be adjusted to be lowercase and have |
title |
(required) String. Title of the output. Vectorized. |
footers |
(optional) Character vector, containing strings of footnotes to be included. Vectorized. |
print.hux |
(optional) Logical, indicating whether the output should be
printed to RTF |
watermark |
(optional) String containing the desired watermark for RTF outputs. Vectorized. |
colheader |
(optional) Character vector that contains the column labels
for a table or listing. Default uses the column labels of |
pagenum |
(optional) Logical. When true page numbers are added on the
right side of the footer section in the format page |
bottom_borders |
(optional) Matrix or |
border_fns |
(optional) List. A list of functions that transform
the matrix passed to |
alignments |
(optional) List of named lists. Vectorized.
(Default = |
Value
A list of formatted huxtables with desired
properties for output to an RTF or HTML.
Huxme Details
For tables and listings, formatting of the output can be dictated through the
formatting columns
(newrows, indentme, boldme, newpage), present in the input dataframe.
The final huxtable will display all columns of the input dataframe, except
any recognized formatting or sorting columns.
For tables, the algorithm uses the column label as first column.
The remaining columns are treated as summary columns.
For graphs, you can pass a ggplot object directly
into huxme and gentlg will save a PNG with with ggplot2::ggsave()
and output an RTF.
Author(s)
Steven Haesendonckx shaesen2@its.jnj.com
Pelagia Alexandra Papadopoulou ppapadop@its.jnj.com
References
https://github.com/hughjonesd/huxtable
Examples
final <- data.frame(
label = c(
"Overall", "Safety Analysis Set",
"Any Adverse event{\\super a}", "- Serious Adverse Event"
),
Drug_A = c("", "40", "10 (25%)", "0"),
Drug_B = c("", "40", "10 (25%)", "0"),
anbr = c(1, 2, 3, 4),
roworder = c(1, 1, 1, 1),
boldme = c(1, 0, 0, 0),
newrows = c(0, 0, 1, 0),
indentme = c(0, 0, 0, 1),
newpage = c(0, 0, 0, 0)
)
# Produce output in rtf format
gentlg(
huxme = final,
wcol = c(0.70, 0.15, 0.15),
file = "TSFAEX",
title = "This is Amazing Demonstration 1",
footers = c(
"Note: For demonstrative purposes only",
"{\\super a} Subjects are counted once for any given event."
)
)
# Pass in column headers instead of using variable name
gentlg(
huxme = final,
wcol = c(0.70, 0.15, 0.15),
file = "TSFAEX",
colheader = c("", "Drug A", "Drug B"),
title = "This is Amazing Demonstration 1",
footers = c(
"Note: For demonstrative purposes only",
"{\\super a} Subjects are counted once for any given event."
)
)
# Add spanning bottom borders under the cells in the second row
gentlg(
huxme = final,
wcol = c(0.70, 0.15, 0.15),
file = "TSFAEX",
colheader = c("", "Drug A", "Drug B"),
title = "This is Amazing Demonstration 1",
footers = c(
"Note: For demonstrative purposes only",
"{\\super a} Subjects are counted once for any given event."
),
border_fns = list(spanning_borders(2))
)
# Use a watermark
gentlg(
huxme = final,
wcol = c(0.70, 0.15, 0.15),
file = "TSFAEX",
colheader = c("", "Drug A", "Drug B"),
title = "This is Amazing Demonstration 1",
footers = c(
"Note: For demonstrative purposes only",
"{\\super a} Subjects are counted once for any given event."
),
watermark = "Confidential"
)
# Set alignments
gentlg(
huxme = final,
file = "TSFAEX",
alignments = list(
# Align the second column to the left
list(row = 1:7, col = 2, value = "left"),
# Align cell "Drug: B" to the right
list(row = 2, col = 3, value = "right")
)
)
# Produce output in HTML format
hux <- gentlg(
huxme = final,
file = "TSFAEX",
colheader = c("", "Drug A", "Drug B"),
title = "This is Amazing Demonstration 1",
footers = c(
"Note: For demonstrative purposes only",
"{\\super a} Subjects are counted once for any given event."
),
watermark = "Confidential",
format = "HTML",
print.hux = FALSE
)
# Export to HTML page
huxtable::quick_html(hux, file = "TSFAEX.html", open = FALSE)
# clean up.
file.remove("TSFAEX.html", "tsfaex.rtf")
Inserts empty rows into a data frame
Description
Inserts empty rows into a data frame
Usage
insert_empty_rows(huxme, newrows = huxme$newrows)
Arguments
huxme |
|
Details
gentlg allows for formatting the input table based on formatting columns
(see gentlg()). One of the formatting mechanisms is empty row insertion. This
function inserts the empty rows based on the newrows column in the data
frame. The new rows are inserted before the rows with value 1 in the
newrows column.
Value
A data frame with added new empty rows.
Generate nested count/percent for two or three levels
Description
This will call freq() multiple times and combine the levels together. This
is useful for adverse event and concomitant medications.
Usage
nested_freq(
df,
denom_df = df,
colvar = NULL,
tablebyvar = NULL,
rowvar = NULL,
rowbyvar = NULL,
statlist = getOption("tidytlg.nested_freq.statlist.default"),
decimal = 1,
cutoff = NULL,
cutoff_stat = "pct",
subset = TRUE,
descending_by = NULL,
display_missing = FALSE,
rowtext = NULL,
row_header = NULL,
.keep = TRUE,
.ord = FALSE,
...
)
Arguments
df |
(required) dataframe containing the two levels to summarize |
denom_df |
(optional) dataframe containing records to use as the
denominator (default = |
colvar |
(required) treatment variable within |
tablebyvar |
(optional) repeat entire table by variable within |
rowvar |
(required) nested levels separated by a star, for example
|
rowbyvar |
(optional) repeat |
statlist |
(optional) count/percent type to return
|
decimal |
(optional) decimal precision root level |
cutoff |
(optional) numeric value used to cut the data to a percentage threshold, if any column meets the threshold the entire record is kept. |
cutoff_stat |
(optional) The value to cutoff by, n or pct. (default = 'pct') |
subset |
(optional) An R expression that will be passed to a
|
descending_by |
(optional) The column or columns to sort descending
values by. Can also provide a named list to do ascending order. ex.
|
display_missing |
(optional) Should the "missing" values be displayed?
(default = |
rowtext |
(optional) A character vector used to rename the |
row_header |
(optional) A character vector to be added to the table. |
.keep |
(optional) Should the |
.ord |
Should the ordering columns be output with the table? This is useful if a table needs to be merged or reordered in any way after build. |
... |
(optional) Named arguments to be included as columns on the table. |
Value
A dataframe of nested results by colvar and optional tablebyvar.
There are a few additional variable sets added to support multiple
requirements.
The level variables (level1_, level2_,
level3_) will carry down the counts for each level to every record. This
allows for easy sorting of nested groups.
The header variables
(header1, header2, header3) will flag the header for each level to
ensure each level header is sorted to the top of the level.
The n
variables ("n_") provide a numeric variable containing frequency for each
colvar. This can be used to sort and filter records.
The pct
variables ("pct_") provide a numeric variable containing percentages for
each colvar. This can be used to sort and filter records.
Examples
adae <- data.frame(
SITEID = c("100", "100", "100", "200", "200", "200"),
USUBJID = c(
"Demo1-101", "Demo1-102", "Demo1-103",
"Demo1-104", "Demo1-105", "Demo1-106"
),
AEBODSYS = c(
"Cardiac disorders", "Cardiac disorders",
"Respiratory, thoracic and mediastinal disorders",
"Infections and infestations",
"Skin and subcutaneous tissue disorders",
"Infections and infestations"
),
AEDECOD = c(
"Arrhythmia supraventricular", "Cardiac failure",
"Chronic obstructive pulmonary disease", "Pneumonia",
"Pustular psoriasis", "Upper respiratory tract infection"
),
colnbr = structure(
c(1L, 2L, 3L, 1L, 2L, 3L),
.Label = c("Active", "Placebo", "Comparator"),
class = "factor"
)
)
# Frequency and percent for two levels of nesting
nested_freq(adae,
colvar = "colnbr",
rowvar = "AEBODSYS*AEDECOD",
statlist = statlist("n (x.x%)")
)
# Frequency and percent for three levels of nesting (for illustrative
# purpose)
nested_freq(adae,
colvar = "colnbr",
rowvar = "SITEID*AEBODSYS*AEDECOD",
statlist = statlist("n (x.x%)")
)
# Cut records where pct meets threshold for a any column
nested_freq(cdisc_adae,
colvar = "TRTA",
rowvar = "AEBODSYS*AEDECOD",
statlist = statlist("n (x.x%)", distinct = TRUE),
cutoff = 2,
cutoff_stat = "n"
)
# Cut records where pct meets threshold for a specific column
nested_freq(cdisc_adae,
rowvar = "AEBODSYS*AEDECOD",
colvar = "TRTAN",
statlist = statlist("n (x.x%)", distinct = TRUE),
cutoff = "54 >= 2",
cutoff_stat = "n"
)
# Frequency and percent for two levels of nesting and sort by descending
# active
nested_freq(adae,
colvar = "colnbr",
rowvar = "AEBODSYS*AEDECOD",
statlist = statlist("n (x.x%)"),
descending = "Active"
)
# Below illustrates how make the same calls to nested_freq() as above, using
# table and # column metadata along with generate_results().
column_metadata <- tibble::tribble(
~tbltype, ~coldef, ~decode,
"type1", "1", "Placebo",
"type1", "2", "Low",
"type1", "3", "High"
)
# Frequency and percent for two levels of nesting
table_metadata <- tibble::tribble(
~anbr, ~func, ~df, ~rowvar, ~tbltype, ~colvar, ~statlist,
"1", "nested_freq", "cdisc_adae", "AEBODSYS*AEDECOD", "type1", "TRTP",
statlist("n (x.x%)")
)
# generate_results(table_metadata,
# column_metadata_file = tidytlg_metadata(path)
# Frequency and percent for three levels of nesting (for illustrative purpose)
table_metadata <- tibble::tribble(
~anbr, ~func, ~df, ~rowvar, ~tbltype, ~colvar,
~statlist,
"1", "nested_freq", "cdisc_adae", "SITEID*AEBODSYS*AEDECOD", "type1",
"TRTP", statlist("n (x.x%)")
)
# Commented out because it takes too long
# generate_results(table_metadata, column_metadata)
# Cut records where pct meets threshold for a any column
column_metadata <- tibble::tribble(
~tbltype, ~coldef, ~decode,
"type2", "1", "Placebo",
"type2", "2", "Active"
)
table_metadata <- tibble::tibble(
anbr = "1", func = "nested_freq", df = "cdisc_adae",
rowvar = "AEBODSYS*AEDECOD",
tbltype = "type2", colvar = "TRTP", statlist = statlist("n (x.x%)"),
dotdotdot = "cutoff = 5"
)
# generate_results(table_metadata,
# column_metadata_file = tidytlg_metadata(path)
# Cut records where pct meets threshold for a specific column
table_metadata <- tibble::tibble(
anbr = "1", func = "nested_freq", df = "cdisc_adae",
rowvar = "AEBODSYS*AEDECOD",
tbltype = "type2", colvar = "TRTP", statlist = statlist("n (x.x%)"),
dotdotdot = "cutoff = 'col1 >= 5'"
)
# generate_results(table_metadata,
# column_metadata_file = tidytlg_metadata(path)
# Frequency and percent for two levels of nesting and sort by descending col1
table_metadata <- tibble::tibble(
anbr = "1", func = "nested_freq", df = "cdisc_adae",
rowvar = "AEBODSYS*AEDECOD",
tbltype = "type2", colvar = "TRTP", statlist = statlist("n (x.x%)"),
dotdotdot = "descending = 'col1'"
)
# generate_results(table_metadata,
# column_metadata_file = tidytlg_metadata(path)
Removes all borders from the table
Description
Removes all borders from the table
Usage
no_borders(ht, matrix = NULL)
Arguments
ht |
|
matrix |
|
See Also
Other border_functions:
col_borders(),
row_border(),
single_border(),
spanning_borders()
Adds bottom borders according to the old formatting
Description
This function is vectorized over its arguments.
Usage
old_format(ht, colspan, colheader, tlf)
Arguments
ht |
the |
colspan |
|
colheader |
|
tlf |
|
Value
a bottom border matrix for use with add_bottom_borders() or NULL
if ht is NULL
Removes no-op padding from an RTF markup
Description
Removes no-op padding from an RTF markup
Usage
remove_zero_padding(rtf)
Arguments
rtf |
|
Details
Removes no-op padding, which is padding that has a thickness of zero from an RTF markup.
Value
character(1) RTF markup with removed zero padding
Replace NA with ""
Description
Used to swap in "" for by variables so the headers sort correctly to the top
Usage
replace_na_with_blank(x)
Arguments
x |
variable to check for NA and replace with "". |
Value
x with NAs replaced with "". Factors will add "" as the first level.
Examples
replace_na_with_blank(c("a", "b", NA))
replace_na_with_blank(factor(c("a", "b", NA), levels = c("a", "b")))
Get Titles and Footnotes for all TLGs or one specific TLG
Description
Get Titles and Footnotes for all TLGs or one specific TLG
Usage
rmdpstitle(
df,
tblid,
idvar = "tblid",
identifier = "identifier",
text = "text"
)
Arguments
df |
dataframe with three variables; table name, row identifier ( |
tblid |
character vector containing the table id, optional, used to
subset |
idvar |
character vector containing the variable in |
identifier |
character vector containing the variable name in |
text |
character vector containing the variable name in |
Value
list of length two, the first element contains the titles
as a tibble and the second contains the footnotes as a list.
Examples
tblid <- "TSIDEM01"
titles <- tibble::tribble(
~tblid, ~identifier, ~text,
"TSIDEM01", "TITLE", "Demographics Example",
"TSIDEM01", "FOOTNOTE1", "Example footnote."
)
title_foot <- rmdpstitle(titles, tblid)
title_foot[[1]]
title_foot[[2]]
SAS rounding in R
Description
roundSAS is an alternative rounding function, ensuring that decimals equal or
bigger than 5 are rounded upwards to the nearest number and returned as
character vector.
Usage
roundSAS(x, digits = 0, as_char = FALSE, na_char = NULL)
Arguments
x |
Numeric vector. |
digits |
An integer specifying the number of decimal places to be displayed after rounding. Default is 0. |
as_char |
logical value indicating conversion of rounded numerical
vector to character vector; default is |
na_char |
A character string indicating missing value; if not specified,
|
Details
At the midpoint of a decimal place (e.g. 0.5, 1.5), the round function in R
rounds to the nearest even number (i.e. 0.5 is rounded to 0; 1.5 is rounded
to 2), whereas SAS rounds to the nearest number (i.e. 0.5 is rounded to 1;
1.5 is rounded to 2). The roundSAS function is an alternative rounding
function for R that ensures rounding to the nearest number, as done in SAS.
roundSAS comes from this Stack Overflow
post.
Value
character vector of rounded values
Examples
### input data vector with midpoint decimals
x <- c(-2.5, -1.5, -0.5, 0.5, 1.5, 2.5)
### rounds to integer
roundSAS(x, digits = 0)
### input data vector with a missing value
y <- c(8.65, 8.75, NA, 9.85, 9.95)
### rounds to tenths and label the missing value with "NE"
roundSAS(y, digits = 1, as_char = TRUE, na_char = "NE")
Adds a continuous bottom border under a row
Description
Adds a continuous bottom border under a row
Usage
row_border(row)
Arguments
row |
|
See Also
Other border_functions:
col_borders(),
no_borders(),
single_border(),
spanning_borders()
Adds a border under a cell
Description
Adds a border under a cell
Usage
single_border(row, col)
Arguments
row |
|
col |
|
See Also
Other border_functions:
col_borders(),
no_borders(),
row_border(),
spanning_borders()
Adds borders under cells in a row, excluding the first column.
Description
Adds borders under cells that are not empty in a given row, omitting the first column of the row. The borders do not touch each other - they are separate.
Usage
spanning_borders(row, cols = c(-1))
Arguments
row |
|
cols |
|
See Also
Other border_functions:
col_borders(),
no_borders(),
row_border(),
single_border()
Spanning headers for outputs
Description
This will create the list object to be passed to gentlg() You can create as
many spanning headers as you like, just add variables prefixed with span to
the column metadata.
Usage
spanning_headers(column_metadata)
Arguments
column_metadata |
dataframe containing the column metadata that is
passed to |
Value
List of character vectors containing column headers for an output.
Examples
column_metadata <-
tibble::tribble(
~tbltype, ~coldef, ~decode, ~span1,
"type1", "0", "Placebo", "",
"type1", "54", "Low Dose", "Xanomeline",
"type1", "81", "High Dose", "Xanomeline",
"type1", "54+81", "Total Xanomeline", ""
)
spanning_headers(column_metadata)
Create a statlist interface for a table
Description
The statlist is the interface for the presentation of data in a tidytlg
table.
Usage
statlist(stats, ...)
Arguments
stats |
(required) A character vector of statistics to display in the table. |
... |
(optional) Additional configuration for stats. See sections below for allowable arguments. |
Value
A statlist object that can be passed in the statlist argument of
freq, nested_freq, or univar.
Statlists for freq() and nested_freq()
freq() statlists can be composed of n (count), N (denominator), and
x.x (percentage, formatted with or without a percent sign).
Denominators will include missing values if the 'display_missing'
argument is TRUE, otherwise they will be excluded. They can be arranged
in the following ways:
nn/Nn (x.x)n (x.x%)n/N (x.x)n/N (x.x%)
The following other configurations are supported:
denoms_by- Controls what groupings of variables should define the denominator. Variables should be passed as a quoted vectordistinct- A boolean value. Should the numerator reflect distinctUSUBJIDsor event counts. Defaults toTRUEwhich captures distinct subjects.distinct_by- A character value used to select the variable that should be used to "distinct" the frequency tables. Defaults toUSUBJID.zero_denom- The string to display when there are no records found in an entire denominator group. Defaults to-zero_n- The string to display when there are no records found for a numerator. Defaults to0.
Statlists for univar statlists
NSUMMEANGeoMEANSDSECVGSDGSEMEANSDMEANSEMEDIANMINMAXRANGEQ1Q3IQRANGEMEDRANGEMEDIQRANGEMEAN_CIGeoMEAN_CI
where GeoMEAN: Geometric Mean, CV: Coefficient of Variation,
GSD: Geometric standard deviation, GSE: Geometric standard error,
MEAN_CI: Mean (95% C.I.), GeoMEAN_CI: Geometric Mean (95% C.I.).
In calculating geometric statistics, if there
are zero values in the inputs, zero values will be excluded before
calculating geometric statistics.
Examples
freq(
mtcars,
colvar = "gear",
rowvar = "cyl",
rowbyvar = "am",
statlist = statlist("n/N (x.x)",
distinct = FALSE,
denoms_by = c("gear", "am"),
zero_denom = "_0_"
)
)
Metadata describing the data, functions and arguments needed to produce your results.
Description
Metadata describing the data, functions and arguments needed to produce your results.
Usage
table_metadata
Format
A data frame with one row per function call and 16 variables:
funcname of the function you wish to call
dfdata frame to pass to the function call
subsetfilter
dfrecords, this is passed directly to filter, ex."AESER == 'Y'"rowvarvariable being summarized that will pass to the function call
rowtextrow label text to display in the table
row_headerheader text to display above row summary
statlistlist of statistics in the analysis, see individual functions for what is available per function (e.g.
"N, n (x.x)")colvarvariable used to determine the columns of the table
decimaldecimal precision
rowbyvarrepeat
rowvarsummary by this variable/s, comma separated for multiple (e.g."ETHNIC, AGEGR1")tablebyvarrepeat the entire table summary by this variable/s, comma separated for multiple (e.g.
"ETHNIC, AGEGR1")denom_dfused to set denominators if
dfdoes not contain all required records
Helper functions for returning files used in gentlg
Description
Helper functions for returning files used in gentlg
Usage
tidytlg_titles(path)
tidytlg_metadata(path)
Arguments
path |
Working directory of the project |
Value
A character vector to the requested file.
Setup data to support the specified column type
Description
tlgsetup is useful for preprocessing total columns and columns composed of
other columns. tlgsetup is called internally by generate_results()
and can be run manually for custom tables.
Usage
tlgsetup(
df,
var,
column_metadata_file = NULL,
column_metadata = NULL,
tbltype = NULL
)
Arguments
df |
dataframe of records for analysis. |
var |
character vector that identifies the numeric column/treatment variable. |
column_metadata_file |
A file containing the column metadata. Read in
with |
column_metadata |
A dataframe containing the column metadata. This will
be used in place of |
tbltype |
A value used to subset the |
Value
dataframe with observations added to support the column type as well
as the factor variable colnbr which is used as our new column summary
variable. Regardless of if a coldef exists in data,
the column will exist in the table.
Examples
df <-
tibble::tribble(
~TRT01AN, ~USUBJID,
0, "A",
54, "B",
81, "C"
)
tlgsetup(df, "TRT01AN", column_metadata = column_metadata)
# Using a dataframe of column metadata
column_metadata <-
tibble::tribble(
~tbltype, ~coldef, ~decode, ~span1,
"type1", "0", "Placebo", "",
"type1", "54", "Low Dose", "Xanomeline",
"type1", "81", "High Dose", "Xanomeline",
"type1", "54+81", "Total Xanomeline", ""
)
tlgsetup(df, "TRT01AN", column_metadata = column_metadata)
Descriptive statistics
Description
Univariate statistics for a variables by treatment and/or group.
Usage
univar(
df,
colvar = NULL,
tablebyvar = NULL,
rowvar = NULL,
rowbyvar = NULL,
statlist = getOption("tidytlg.univar.statlist.default"),
decimal = 1,
precisionby = NULL,
precisionon = NULL,
wide = FALSE,
alpha = 0.05,
rowtext = NULL,
row_header = NULL,
.keep = TRUE,
.ord = FALSE,
...
)
Arguments
df |
(required) dataframe containing records to summarize by treatment. |
colvar |
(required) character vector of the treatment variable within the dataframe. |
tablebyvar |
(optional) repeat entire table by variable within |
rowvar |
(required) character vector of variable to summarize within the dataframe. |
rowbyvar |
(optional) repeat |
statlist |
(optional) |
decimal |
(optional) decimal precision root level, when using
|
precisionby |
(optional) vector of by variable(s) to use when calculating parameter based precision. |
precisionon |
(optional) variable to use when calculating parameter
based precision. If |
wide |
(optional) logical indicating to convert labels to column and
columns to labels (default = |
alpha |
(optional) alpha level for 2-sided confidence interval (default = 0.05). |
rowtext |
(optional) A text string to replace the |
row_header |
(optional) A row to add as a header for the table. |
.keep |
(optional) Should the |
.ord |
Should the ordering columns be output with the table? This is useful if a table needs to be merged or reordered in any way after build. |
... |
(optional) Named arguments to be included as columns on the table. |
Value
dataframe of results
Examples
adsl <-
structure(
list(
USUBJID = c(
"DEMO-101", "DEMO-102", "DEMO-103", "DEMO-104",
"DEMO-105", "DEMO-106"
),
AGE = c(59, 51, 57, 65, 21, 80),
SEX = c("F", "M", "F", "M", "F", "M"),
WEIGHTBL = c(83.6, 75, 84, 90, 65, 70),
colnbr = structure(
c(1L, 3L, 2L, 2L, 3L, 1L),
.Label = c("Placebo", "Low", "High"),
class = "factor"
)
),
row.names = c(NA, 6L),
class = "data.frame"
)
# N, Mean(SD), Median, Range, IQ Range for a rowvar by colvar
univar(adsl,
colvar = "colnbr",
rowvar = "AGE"
)
# N and Mean for a rowvar by colvar
univar(adsl,
colvar = "colnbr",
rowvar = "AGE",
statlist = statlist(c("N", "MEAN"))
)
# N and Mean for a rowvar by colvar and a by variable
univar(adsl,
colvar = "colnbr",
rowvar = "AGE",
rowbyvar = "SEX",
statlist = statlist(c("N", "MEAN"))
)
# Below illustrates how make the same calls to univar() as above, using table
# and column metadata # along with generate_results().
column_metadata <- tibble::tribble(
~tbltype, ~coldef, ~decode,
"type1", "0", "Placebo",
"type1", "54", "Low",
"type1", "81", "High"
)
# N, Mean(SD), Median, Range, IQ Range for a rowvar by colvar
table_metadata <- tibble::tribble(
~anbr, ~func, ~df, ~rowvar, ~tbltype, ~colvar,
"1", "univar", "cdisc_adae", "AGE", "type1", "TRTA"
)
generate_results(table_metadata,
column_metadata = column_metadata,
tbltype = "type1"
)
# N and Mean for a rowvar by colvar
table_metadata <- tibble::tribble(
~anbr, ~func, ~df, ~rowvar, ~tbltype, ~colvar, ~statlist,
"1", "univar", "cdisc_adae", "AGE", "type1", "TRTA",
statlist(c("N", "MEAN"))
)
generate_results(table_metadata,
column_metadata = column_metadata,
tbltype = "type1"
)
# N and Mean for a rowvar by colvar and a by variable
table_metadata <- tibble::tribble(
~anbr, ~func, ~df, ~rowvar, ~tbltype, ~colvar, ~statlist, ~by,
"1", "univar", "cdisc_adae", "AGE", "type1", "TRTA",
statlist(c("N", "MEAN")), "SEX"
)
generate_results(table_metadata,
column_metadata = column_metadata,
tbltype = "type1"
)