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

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

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

2 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 (%)"
)

3 Appendix

3.1 Session information

R version 4.1.0 (2021-05-18)

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

locale: LC_CTYPE=en_US.UTF-8, LC_NUMERIC=C, LC_TIME=en_GB.UTF-8, LC_COLLATE=en_US.UTF-8, LC_MONETARY=en_GB.UTF-8, LC_MESSAGES=en_US.UTF-8, LC_PAPER=en_GB.UTF-8, LC_NAME=C, LC_ADDRESS=C, LC_TELEPHONE=C, LC_MEASUREMENT=en_GB.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.0.1), inTextSummaryTable(v.3.0.1) and knitr(v.1.33)

loaded via a namespace (and not attached): tidyselect(v.1.1.1), xfun(v.0.24), bslib(v.0.2.5.1), reshape2(v.1.4.4), purrr(v.0.3.4), haven(v.2.4.1), colorspace(v.2.0-2), vctrs(v.0.3.8), generics(v.0.1.0), htmltools(v.0.5.1.1), viridisLite(v.0.4.0), yaml(v.2.2.1), base64enc(v.0.1-3), utf8(v.1.2.1), rlang(v.0.4.11), jquerylib(v.0.1.4), pillar(v.1.6.1), glue(v.1.4.2), gdtools(v.0.2.3), uuid(v.0.1-4), lifecycle(v.1.0.0), 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.3), evaluate(v.0.14), forcats(v.0.5.1), crosstalk(v.1.1.1), fansi(v.0.5.0), Rcpp(v.1.0.7), scales(v.1.1.1), DT(v.0.18), jsonlite(v.1.7.2), systemfonts(v.1.0.2), ggplot2(v.3.3.5), hms(v.1.1.0), digest(v.0.6.27), stringi(v.1.6.2), dplyr(v.1.0.7), ggrepel(v.0.9.1), cowplot(v.1.1.1), grid(v.4.1.0), magrittr(v.2.0.1), sass(v.0.4.0), tibble(v.3.1.2), crayon(v.1.4.1), pkgconfig(v.2.0.3), ellipsis(v.0.3.2), data.table(v.1.14.0), xml2(v.1.3.2), rmarkdown(v.2.9), officer(v.0.3.18), flextable(v.0.6.6), R6(v.2.5.0) and compiler(v.4.1.0)