| Title: | Create TLGs using the 'tidyverse' |
|---|---|
| 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. |
| Authors: | Nicholas Masel [aut], Steven Haesendonckx [aut], Pelagia Alexandra Papadopoulou [aut], Sheng-Wei Wang [aut], Eli Miller [aut] (ORCID: <https://orcid.org/0000-0002-2127-9456>), Nathan Kosiba [aut] (ORCID: <https://orcid.org/0000-0001-5359-4234>), Aidan Ceney [aut] (ORCID: <https://orcid.org/0000-0001-8313-487X>), Janssen R&D [cph, fnd], David Hugh-Jones [cph] (Author of included 'huxtable' library), Konrad Pagacz [aut, cre] |
| Maintainer: | Konrad Pagacz <[email protected]> |
| License: | Apache License 2.0 |
| Version: | 0.11.0.9000 |
| Built: | 2026-05-20 09:54:41 UTC |
| Source: | https://github.com/pharmaverse/tidytlg |
huxtable
Adds bottom borders to a huxtable
add_bottom_borders(ht, border_matrix = no_borders(ht), transform_fns = list())add_bottom_borders(ht, border_matrix = no_borders(ht), transform_fns = list())
ht |
|
border_matrix |
(optional) |
transform_fns |
(optional)
The functions in the list are applied sequentially to |
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.
A huxtable with added borders.
border_matrix detailsYou 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.
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 huxtable object,
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().
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")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")
indentme, newrows, newpage, and roworder to
the results dataframeAdd the formatting variables of indentme, newrows, newpage, and roworder to
the results dataframe
add_format(df, tableby = NULL, groupby = NULL, .keep = FALSE)add_format(df, tableby = NULL, groupby = NULL, .keep = FALSE)
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 |
dataframe with the formatting variables indentme, newrows, newpage, and roworder added.
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)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 the indentme variable to your results data. This drives the number of
indents for the row label text (e.g. 0, 1, 2, etc.).
add_indent(df)add_indent(df)
df |
dataframe of results that contains |
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 |
dataframe with the indentme variable added.
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)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)
newrows variable to the results dataframe.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.
add_newrows(df, tableby = NULL, groupby = NULL)add_newrows(df, tableby = NULL, groupby = NULL)
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. |
dataframe with the variable newrows and roworder added.
newrows is used by gentlg to insert line breaks.
# 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")# 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")
tidytlg tables together with formatting variablesbind_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.
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 )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 )
... |
(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 |
The tidytlg tables bound together reflecting the
tablebyvars used.
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")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 datasetADAE data created from subsetting the CDISC ADAE dataset
cdisc_adaecdisc_adae
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
ADURNAE Duration (N)
ADURUAE Duration Units
AETERMReported 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 Signif Disability/Incapacity
AESDTHResults 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 AE Flag
AOCCSFLFirst Occurrence of SOC Flag
AOCCPFLFirst Occurrence of Preferred Term Flag
AOCC02FLFirst Occurrence 02 Flag for Serious
AOCC03FLFirst Occurrence 03 Flag for Serious SOC
AOCC04FLFirst Occurrence 04 Flag for Serious PT
CQ01NAMCustomized Query 01 Name
AOCC01FLFirst Occurrence 01 Flag for CQ01
CDISC SDTM/ADAM Pilot Project.
ADLB data created from subsetting the CDISC ADLB datasetADLB data created from subsetting the CDISC ADLB dataset
cdisc_adlbcdisc_adlb
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
CDISC SDTM/ADAM Pilot Project.
ADSL data created from subsetting the CDISC ADSL with 15 subjects (5 subjects in each arm)ADSL data created from subsetting the CDISC ADSL with 15 subjects (5 subjects in each arm)
cdisc_adslcdisc_adsl
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
MMSETOTMMSE Total
CDISC SDTM/ADAM Pilot Project.
ADVS data created from subsetting the CDISC ADVS datasetADVS data created from subsetting the CDISC ADVS dataset
cdisc_advscdisc_advs
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
CDISC SDTM/ADAM Pilot Project.
Convert character variable to a factor based off it's numeric variable counterpart.
char2factor(df, c_var, n_var)char2factor(df, c_var, n_var)
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. |
A factor.
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)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
col_borders(col, rows)col_borders(col, rows)
col |
|
rows |
|
Other border_functions:
no_borders(),
row_border(),
single_border(),
spanning_borders()
This is used by tlgsetup to prepare you input data to support
the desired column layout.
column_metadatacolumn_metadata
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 TRT01PN
decodedecode of coldef that will display as a column header
in the table
span1spanning 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 for a variable by treatment and/or group.
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, ... )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, ... )
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. |
A dataframe of results
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.
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" )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
generate_results( table_metadata, column_metadata_file = NULL, column_metadata = NULL, env = parent.frame(), tbltype = NULL, add_count = FALSE )generate_results( table_metadata, column_metadata_file = NULL, column_metadata = NULL, env = parent.frame(), tbltype = NULL, add_count = FALSE )
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 |
dataframe of results
tidytlg tableGenerate 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.
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(), footers_one_row = FALSE )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(), footers_one_row = FALSE )
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 one of:
When a single numerical value is used, this will be taken as the column width
for the first column. The other columns will be equally spaced across the
remainder of the available space. Alternatively, a vector can be used to
represent the widths of all columns in the final output. The order of the
arguments needs to correspond to the order of the columns in the |
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 = |
footers_one_row |
(optional) Logical. Whether to export the footers
as a single table row (Default = |
A list of formatted huxtables with desired
properties for output to an RTF or HTML.
Huxme DetailsFor 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.
Steven Haesendonckx [email protected]
Pelagia Alexandra Papadopoulou [email protected]
https://github.com/hughjonesd/huxtable
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") ) ) final_2 <- 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") ) gentlg( huxme = list(final_2, final_2), wcol = list(c(0.70, 0.15, 0.15), c(0.5)), 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." ) ) # 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")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") ) ) final_2 <- 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") ) gentlg( huxme = list(final_2, final_2), wcol = list(c(0.70, 0.15, 0.15), c(0.5)), 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." ) ) # 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")
This function returns the file path up until the program's name.
get_file_name()get_file_name()
The file path up until the program's name.
Steven haesendonckx [email protected]
get_file_name()get_file_name()
Inserts empty rows into a data frame
insert_empty_rows(huxme, newrows = huxme$newrows)insert_empty_rows(huxme, newrows = huxme$newrows)
huxme |
|
newrows |
|
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.
A data frame with added new empty rows.
df <- iris[1:10, ] df <- as.data.frame(apply(df, 2, as.character)) df$newrows <- c(0, 1, 0, 1, 1, 0, 0, 0, 0, 0) insert_empty_rows(df)df <- iris[1:10, ] df <- as.data.frame(apply(df, 2, as.character)) df$newrows <- c(0, 1, 0, 1, 1, 0, 0, 0, 0, 0) insert_empty_rows(df)
This will call freq() multiple times and combine the levels together. This
is useful for adverse event and concomitant medications.
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, ... )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, ... )
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. |
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.
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)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
no_borders(ht, matrix = NULL)no_borders(ht, matrix = NULL)
ht |
|
matrix |
|
Other border_functions:
col_borders(),
row_border(),
single_border(),
spanning_borders()
Used to swap in "" for by variables so the headers sort correctly to the top
replace_na_with_blank(x)replace_na_with_blank(x)
x |
variable to check for NA and replace with "". |
x with NAs replaced with "". Factors will add "" as the first level.
replace_na_with_blank(c("a", "b", NA)) replace_na_with_blank(factor(c("a", "b", NA), levels = c("a", "b")))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
rmdpstitle( df, tblid, idvar = "tblid", identifier = "identifier", text = "text" )rmdpstitle( df, tblid, idvar = "tblid", identifier = "identifier", text = "text" )
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 |
list of length two, the first element contains the titles
as a tibble and the second contains the footnotes as a list.
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]]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]]
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.
roundSAS(x, digits = 0, as_char = FALSE, na_char = NULL)roundSAS(x, digits = 0, as_char = FALSE, na_char = NULL)
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,
|
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.
character vector of rounded values
### 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")### 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
row_border(row)row_border(row)
row |
|
Other border_functions:
col_borders(),
no_borders(),
single_border(),
spanning_borders()
Adds a border under a cell
single_border(row, col)single_border(row, col)
row |
|
col |
|
Other border_functions:
col_borders(),
no_borders(),
row_border(),
spanning_borders()
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.
spanning_borders(row, cols = c(-1))spanning_borders(row, cols = c(-1))
row |
|
cols |
|
Other border_functions:
col_borders(),
no_borders(),
row_border(),
single_border()
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.
spanning_headers(column_metadata)spanning_headers(column_metadata)
column_metadata |
dataframe containing the column metadata that is
passed to |
List of character vectors containing column headers for an output.
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)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)
statlist interface for a tableThe statlist is the interface for the presentation of data in a tidytlg
table.
statlist(stats, ...)statlist(stats, ...)
stats |
(required) A character vector of statistics to display in the table. |
... |
(optional) Additional configuration for stats. See sections below for allowable arguments. |
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:
n
n/N
n (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 vector
distinct - A boolean value. Should the numerator reflect distinct
USUBJIDs or event counts. Defaults to TRUE which captures distinct
subjects.
distinct_by - A character value used to select the variable that
should be used to "distinct" the frequency tables. Defaults to USUBJID.
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 to 0.
Statlists for univar statlists
N
SUM
MEAN
GeoMEAN
SD
SE
CV
GSD
GSE
MEANSD
MEANSE
MEDIAN
MIN
MAX
RANGE
Q1
Q3
IQRANGE
MEDRANGE
MEDIQRANGE
MEAN_CI
GeoMEAN_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.
freq( mtcars, colvar = "gear", rowvar = "cyl", rowbyvar = "am", statlist = statlist("n/N (x.x)", distinct = FALSE, denoms_by = c("gear", "am"), zero_denom = "_0_" ) )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.
table_metadatatable_metadata
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 df records, 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 rowvar summary 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 df does not contain
all required records
gentlg
Helper functions for returning files used in gentlg
tidytlg_titles(path) tidytlg_metadata(path)tidytlg_titles(path) tidytlg_metadata(path)
path |
Working directory of the project |
A character vector to the requested file.
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.
tlgsetup( df, var, column_metadata_file = NULL, column_metadata = NULL, tbltype = NULL )tlgsetup( df, var, column_metadata_file = NULL, column_metadata = NULL, tbltype = NULL )
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 |
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.
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)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)
Univariate statistics for a variables by treatment and/or group.
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, ... )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, ... )
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. |
dataframe of results
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" )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" )