In this vignette we focus on providing more explanation on how the inTextSummaryTable package actually works. We would describe some of the functionalities less exposed to the users.

We assume you are already familiar on how to create and export tables, otherwise we advise to first check out the dedicated vignettes for creating and exporting tables. The vignettes are accessible with the commands below.

vignette("inTextSummaryTable-createTables", "inTextSummaryTable")
vignette("inTextSummaryTable-exportTables", "inTextSummaryTable")

We will first create example data sets to show how the exporting functionalities work. The data sets used are available in the clinUtils package.

library(inTextSummaryTable)
library(clinUtils)
library(pander)
library(tools) # toTitleCase
# load example data
data(dataADaMCDISCP01)

dataAll <- dataADaMCDISCP01
labelVars <- attr(dataAll, "labelVars")
dataAE <-  subset(dataAll$ADAE, SAFFL == "Y" & TRTEMFL == "Y")
dataAEInterest <- subset(dataAE, AESOC %in% c(
        "INFECTIONS AND INFESTATIONS",
        "GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS"
    )
)

# ensure that order of elements is the one specified in 
# the corresponding numeric variable
dataAEInterest$TRTA <- reorder(dataAEInterest$TRTA, dataAEInterest$TRTAN)
dataAEInterest$AESEV <- factor(dataAEInterest$AESEV, levels = c("MILD", "MODERATE"))

dataTotalAE <- subset(dataAll$ADSL, TRT01A != "Placebo")
# should contain columns specified in 'colVar'
dataTotalAE$TRTA <- dataTotalAE$TRT01A 

1 Detailed framework of the creation of the in-text table

The getSummaryStatisticsTable consists of the following framework:

  • computation of the summary statistics table with the computeSummaryStatisticsTable function
  • export of the table to the required format with the outputType parameter

1.1 Computation of the summary statistics

The supporting data for the summary statistics table, is accessed via the computeSummaryStatisticsTable. This includes the entire set of statistics (as numeric) and combined statistic set.

The output from the computeSummaryStatisticsTable is equivalent of the table output by the getSummaryStatisticsTable function when the outputType is set to ‘data.frame-base’.

summaryTable <- computeSummaryStatisticsTable(
    data = dataAEInterest,
    rowVar = c("AESOC", "AEDECOD"),
    rowVarTotalInclude = c("AESOC", "AEDECOD"),
    colVar = "TRTA",
    stats = getStats("n (%)"),
    dataTotal = dataTotalAE,
    labelVars = labelVars,
    rowVarLab = c('AESOC' = "TEAE by SOC and Preferred Term\nn (%)")
)

pander(head(summaryTable, 3))
Table continues below
AESOC AEDECOD
GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS APPLICATION SITE DERMATITIS
GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS APPLICATION SITE ERYTHEMA
GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS APPLICATION SITE IRRITATION
Table continues below
TRTA isTotal statN statm statPercTotalN statPercN
Xanomeline Low Dose FALSE 0 0 2 0
Xanomeline Low Dose FALSE 2 2 2 100
Xanomeline Low Dose FALSE 1 2 2 50
n (%)
0
2 (100)
1 (50.0)

Please note the presence of the isTotal column, which flags the records containing the number of subjects reported in the table header.

pander(subset(summaryTable, isTotal))
Table continues below
  AESOC AEDECOD TRTA isTotal statN statm
13 NA NA Xanomeline Low Dose TRUE 2 2
26 NA NA Xanomeline High Dose TRUE 3 3
  statPercTotalN statPercN n (%)
13 2 100 2 (100)
26 3 100 3 (100)

1.2 Export table to the requested format

The summary table is exported to the format of interest with:

export(
    summaryTable = summaryTable,
    outputType = "flextable"
)

Please see the vignette: inTextSummaryTable-exportTables for more information on the different export types available.

2 Combine summary statistics table

Summary statistics tables can be combined with the combine function.

tableDemoCat <- computeSummaryStatisticsTable(
    data = dataADaMCDISCP01$ADSL,
    var = c("SEX", "AGE"), varInclude0 = TRUE,
    colVar = "TRT01P",
    stats = getStats("n (%)", includeName = FALSE),
    labelVars = labelVars
)
tableDemoCont <- computeSummaryStatisticsTable(
    data = dataADaMCDISCP01$ADSL,
    var = c("HEIGHTBL", "WEIGHTBL"),
    colVar = "TRT01P",
    stats = getStats(c("n", "median (range)")),
    labelVars = labelVars
)
tableDemo <- combine(tableDemoCat, tableDemoCont)
export(tableDemo)

3 Data pre-processing

The variables used for the row and columns of the summary statistics tables should be present in a long format in the input data for the getSummaryStatisticsTable function. s In case the grouping of the rows/columns is more complex and no grouping variable is yet available in the data, the function combineVariables offers simpler functionalities to create the input data.

The label for the grouping is extracted from the SAS dataset labels if labelVars is specified, or can be customized (label parameter).

For example, the adverse events are counted for different population set: screened population, completer population, only events with high severity, or related to the treatment and with high severity.

# prepare the data: create grouping of interest
dataAEGroup <- combineVariables(
    data = dataAEInterest,
    newVar = "AEGRP",
    paramsList = list(
        # for all screened patients
        list(var = "TRTA", value = "Xanomeline High Dose"),
        # for moderate severity
        list(var = "AESEV", value = "MODERATE", labelExtra = "Moderate"),
        list(var = "AENDY", label = paste("With adverse events ending date"))
    ),
    # include also counts for all records
    includeAll = TRUE,
    labelAll = "All Adverse events", 
    labelVars = labelVars
)
labelVars["AEGRP"] <- "Patient groups of interest"

# create the table
getSummaryStatisticsTable(
    data = dataAEGroup,
    colVar = "TRTA", 
    rowVar = "AEGRP", 
    labelVars = labelVars,
    dataTotal = dataTotalAE,
    stats = list(expression(paste0(statN, " (", round(statPercN, 1), ")"))),
    title = "Table: Adverse events: counts for groups of interest",
    footer = "Statistics: n (%)"
)

4 Appendix

4.1 Session information

R version 4.1.2 (2021-11-01)

Platform: x86_64-pc-linux-gnu (64-bit)

locale: LC_CTYPE=en_US.UTF-8, LC_NUMERIC=C, LC_TIME=en_US.UTF-8, LC_COLLATE=C, LC_MONETARY=en_US.UTF-8, LC_MESSAGES=en_US.UTF-8, LC_PAPER=en_US.UTF-8, LC_NAME=C, LC_ADDRESS=C, LC_TELEPHONE=C, LC_MEASUREMENT=en_US.UTF-8 and LC_IDENTIFICATION=C

attached base packages: tools, stats, graphics, grDevices, utils, datasets, methods and base

other attached packages: pander(v.0.6.4), clinUtils(v.0.1.1), inTextSummaryTable(v.3.1.1) and knitr(v.1.37)

loaded via a namespace (and not attached): tidyselect(v.1.1.1), xfun(v.0.29), reshape2(v.1.4.4), purrr(v.0.3.4), haven(v.2.4.3), colorspace(v.2.0-3), vctrs(v.0.3.8), generics(v.0.1.2), htmltools(v.0.5.2), viridisLite(v.0.4.0), yaml(v.2.3.5), base64enc(v.0.1-3), utf8(v.1.2.2), rlang(v.1.0.1), jquerylib(v.0.1.4), pillar(v.1.7.0), glue(v.1.6.1), gdtools(v.0.2.4), uuid(v.1.0-3), lifecycle(v.1.0.1), plyr(v.1.8.6), stringr(v.1.4.0), munsell(v.0.5.0), gtable(v.0.3.0), zip(v.2.2.0), htmlwidgets(v.1.5.4), evaluate(v.0.15), forcats(v.0.5.1), fastmap(v.1.1.0), crosstalk(v.1.2.0), fansi(v.1.0.2), Rcpp(v.1.0.8), scales(v.1.1.1), DT(v.0.20), systemfonts(v.1.0.4), ggplot2(v.3.3.5), hms(v.1.1.1), digest(v.0.6.29), stringi(v.1.7.6), dplyr(v.1.0.8), ggrepel(v.0.9.1), cowplot(v.1.1.1), grid(v.4.1.2), cli(v.3.2.0), magrittr(v.2.0.2), tibble(v.3.1.6), crayon(v.1.5.0), pkgconfig(v.2.0.3), ellipsis(v.0.3.2), data.table(v.1.14.2), xml2(v.1.3.3), rmarkdown(v.2.11), officer(v.0.4.1), flextable(v.0.6.10), R6(v.2.5.1) and compiler(v.4.1.2)