Title: | Creation of in-Text Summary Table |
---|---|
Description: | Creation of tables of summary statistics or counts for clinical data (for 'TLFs'). These tables can be exported as in-text table (with the 'flextable' package) for a Clinical Study Report (Word format) or a 'topline' presentation (PowerPoint format), or as interactive table (with the 'DT' package) to an html document for clinical data review. |
Authors: | Laure Cougnaud [aut, cre], Michela Pasetto [aut], Margaux Faes [rev] (tests), Open Analytics [cph] |
Maintainer: | Laure Cougnaud <[email protected]> |
License: | MIT + file LICENSE |
Version: | 3.3.3 |
Built: | 2025-02-08 03:37:55 UTC |
Source: | https://github.com/openanalytics/intextsummarytable |
Filter variables not present in the data or in reference set with a warning, and only returned filtered vector, or NULL if empty.
checkVar( var, varLabel, varUncheck = NULL, varRef, refLabel = ifelse(!missing(varRef), "reference variable", "data"), data, msgType = c("warning", "error") )
checkVar( var, varLabel, varUncheck = NULL, varRef, refLabel = ifelse(!missing(varRef), "reference variable", "data"), data, msgType = c("warning", "error") )
var |
String with variable to check. |
varLabel |
String with label for |
varUncheck |
(Named) character vector with extra variables
in |
varRef |
(Named) character vector with set of reference variables. |
refLabel |
String with label for the reference |
data |
Data.frame with data. |
msgType |
String with type of message returned, either a 'warning' (default) or an error. |
Depending on msgType
:
warning
: warning is printed in the console, and a
var
filtered with element not in data
or in refSet
is returned.
If filtered var
is empty, NULL is returned.
error
: an error is triggered.
Laure Cougnaud
varLabInclude
variable.This function ensures that:
variable name is included if more than one variable are specified
variable name is not included if no variable is specified
checkVarLabInclude(var, varLabInclude = length(var) > 1)
checkVarLabInclude(var, varLabInclude = length(var) > 1)
var |
String with variable to check. |
varLabInclude |
Logical, if TRUE
the name of the summary statistic variable(s) ( |
(Updated) varLabInclude
Laure Cougnaud
Combine objects
combine(...)
combine(...)
... |
Extra parameters for the corresponding method. |
combine.summaryTable
to combine summaryTable
objects.
A new table is created, combining the tables by rows.
The attributes of the combined summary table are obtained by combining the attributes of all summary tables (and removing duplicates).
## S3 method for class 'summaryTable' combine(..., summaryTables, combineVar = NULL, combineDir = c("row", "col"))
## S3 method for class 'summaryTable' combine(..., summaryTables, combineVar = NULL, combineDir = c("row", "col"))
... |
|
summaryTables |
List of |
combineVar |
(optional) String with name
of a new variable tracking from which table
each record originally come from. |
combineDir |
String indicating
on which direction: 'row' or 'col' (a.k.a column)
the information on the table appartenance
( |
In case only a set of tables contain categorical variable,
in nested rows, so the variable
and variableGroup
variables, these variables are included as last in
the 'row variables' attribute of the combined table.
Only one row is retained for the columns totals
per column variable (the first one in order of appearance).
The column totals are not included if the column
variable(s) are not the same across tables, or
if the totals differ between tables.
A combined summaryTable
.
Laure Cougnaud
Combine the column total for a combined summary table
combineColTotal(summaryTable, attrs)
combineColTotal(summaryTable, attrs)
summaryTable |
Combined summary table |
attrs |
Nested list with attributes of each summary table. |
summary table, with combined total columns
Laure Cougnaud
This typically converts the data from a wide to a long format. For each variable, a subset of interest based on a condition can be specified.
combineVariables( data, paramsList, newVar, labelVars = NULL, fctTest = "==", includeAll = FALSE, labelAll = "Any" )
combineVariables( data, paramsList, newVar, labelVars = NULL, fctTest = "==", includeAll = FALSE, labelAll = "Any" )
data |
Data.frame with dataset to consider for the summary table. |
paramsList |
nested list of parameters,
specifying how the records of interest should be selected.
|
newVar |
String with name of new variable to construct. |
labelVars |
(optional) Named character vector with label for
the row, column variable(s) or variable(s) to summarize. |
fctTest |
Default function to use to compare |
includeAll |
Logical, if TRUE (FALSE by default) include also the entire data as an additional subgroup. |
labelAll |
String of group label for the entire data in case |
Data.frame with records from data
extracted based on
the different conditions specified in paramsList
.
This data.frame contains an additional variable
(labelled based on newVar
) mentioning the
specific condition for which the record was extracted
(based label
, labelExtra
, labelVars
).
This variable is a factor whose levels are ordered based on the order
of the condition specified in paramsList
.
Laure Cougnaud
Additionally, this function run extra checks on the data:
an error message is triggered if any subject (identified by subjectVar
)
have different values in a continuous var
an indicative message is triggered if multiple but identical records are available
for subjectVar
and a continuous var
computeSummaryStatistics( data, var = NULL, varTotalInclude = FALSE, statsExtra = NULL, subjectVar = "USUBJID", filterEmptyVar = TRUE, type = "auto", checkVarDiffBySubj = c("error", "warning", "none"), msgLabel = NULL, msgVars = NULL )
computeSummaryStatistics( data, var = NULL, varTotalInclude = FALSE, statsExtra = NULL, subjectVar = "USUBJID", filterEmptyVar = TRUE, type = "auto", checkVarDiffBySubj = c("error", "warning", "none"), msgLabel = NULL, msgVars = NULL )
data |
Data.frame with dataset to consider for the summary table. |
var |
Character vector with variable(s) of |
varTotalInclude |
Logical (FALSE by default)
Should the total across all categories of |
statsExtra |
(optional) Named list with functions for additional custom
statistics to be computed.
For example, to additionally compute the coefficient of variation, this can be set to:
|
subjectVar |
String, variable of |
filterEmptyVar |
Logical, if TRUE doesn't return any results if the variable is empty, otherwise return 0 for the counts and NA for summary statistics. Criterias to consider a variable empty are:
By default, an empty variable are filtered. |
type |
String with type of table:
|
checkVarDiffBySubj |
String, 'error' (default), 'warning',
or 'none'.
Should an error, a warning, or nothing be produced
if a continuous variable ( |
msgLabel |
(optional) String with label for the data (NULL by default), included in the message/warning for checks. |
msgVars |
(optional) Character vector with columns of |
Data.frame with summary statistics in columns,
depending if type
is:
'summary':
'statN': number of subjects
'statm': number of records
'statMean': mean of var
'statSD': standard deviation of var
'statSE': standard error the mean of var
'statMedian': median of var
'statMin': minimum of var
'statMax': maximum of var
'count':
'variableGroup': factor with groups of var
for which counts are reported
'statN': number of subjects
'statm': number of records
Laure Cougnaud
Compute summary statistics for a specific dataset and variables of interest
computeSummaryStatisticsTable( data, var = NULL, varFlag = NULL, varInclude0 = FALSE, varLab = NULL, varLabInclude = length(var) > 1, varGeneralLab = "Variable", varSubgroupLab = "Variable group", varIgnore = NULL, varIncludeTotal = FALSE, varTotalInclude = FALSE, varTotalInSepRow = FALSE, colVar = NULL, colVarDataLevels = NULL, colVarTotal = colVar, colVarTotalPerc = colVarTotal, colTotalInclude = FALSE, colTotalLab = "Total", colInclude0 = FALSE, rowVar = NULL, rowVarDataLevels = NULL, rowVarLab = NULL, rowOrder = "auto", rowOrderTotalFilterFct = NULL, rowOrderCatLast = NULL, rowVarTotalInclude = NULL, rowVarTotalInSepRow = NULL, rowVarTotalByVar = NULL, rowVarTotalPerc = NULL, rowInclude0 = FALSE, type = "auto", subjectVar = "USUBJID", dataTotal = NULL, dataTotalPerc = dataTotal, dataTotalRow = NULL, dataTotalCol = NULL, stats = NULL, statsVarBy = NULL, statsExtra = NULL, statsGeneralLab = "Statistic", statsPerc = c("statN", "statm"), filterFct = NULL, labelVars = NULL, byVar = NULL, byVarLab = NULL, checkVarDiffBySubj = "error" )
computeSummaryStatisticsTable( data, var = NULL, varFlag = NULL, varInclude0 = FALSE, varLab = NULL, varLabInclude = length(var) > 1, varGeneralLab = "Variable", varSubgroupLab = "Variable group", varIgnore = NULL, varIncludeTotal = FALSE, varTotalInclude = FALSE, varTotalInSepRow = FALSE, colVar = NULL, colVarDataLevels = NULL, colVarTotal = colVar, colVarTotalPerc = colVarTotal, colTotalInclude = FALSE, colTotalLab = "Total", colInclude0 = FALSE, rowVar = NULL, rowVarDataLevels = NULL, rowVarLab = NULL, rowOrder = "auto", rowOrderTotalFilterFct = NULL, rowOrderCatLast = NULL, rowVarTotalInclude = NULL, rowVarTotalInSepRow = NULL, rowVarTotalByVar = NULL, rowVarTotalPerc = NULL, rowInclude0 = FALSE, type = "auto", subjectVar = "USUBJID", dataTotal = NULL, dataTotalPerc = dataTotal, dataTotalRow = NULL, dataTotalCol = NULL, stats = NULL, statsVarBy = NULL, statsExtra = NULL, statsGeneralLab = "Statistic", statsPerc = c("statN", "statm"), filterFct = NULL, labelVars = NULL, byVar = NULL, byVarLab = NULL, checkVarDiffBySubj = "error" )
data |
Data.frame with dataset to consider for the summary table. |
var |
Character vector with variable(s) of |
varFlag |
Character vector, subset of |
varInclude0 |
Logical, should rows with no counts
for the count
|
varLab |
Named character vector with label for each variable
specified in |
varLabInclude |
Logical, if TRUE
the name of the summary statistic variable(s) ( |
varGeneralLab |
String with general label for variable specified in |
varSubgroupLab |
String with general label for sub-group of categorical variable(s) for count table, 'Variable group' by default. This will be included in the final table header (see 'rowVarLab' attribute of the output). |
varIgnore |
Vector with elements to ignore in the |
varIncludeTotal |
This argument is deprecated, please use: 'varTotalInclude' instead. |
varTotalInclude |
Should the total across all categories of
|
varTotalInSepRow |
Logical, should the total per variable be included in a separated row (by default) or in the row containing the header of the variable? |
colVar |
Character vector with variable(s) to be included in columns.
If multiple variables are specified, the variables should
be sorted in hierarchical order,
and are included in multi-columns layout. |
colVarDataLevels |
Data.frame with unique combinations of |
colVarTotal |
String with column(s) considered to compute the total by,
reported in the header of the table, by default same as |
colVarTotalPerc |
String with column(s) considered to compute the total by,
used as denominator for the percentage computation, by default same as |
colTotalInclude |
Logical, if TRUE (FALSE by default) include the summary statistics across columns in a separated column. |
colTotalLab |
String, label for the total column 'Total' by default. |
colInclude0 |
Logical, if TRUE (FALSE by default),
include columns with no records, based on all combinations
of the |
rowVar |
Character vector with variable(s) to be included in the rows. If multiple variables are specified, the variables should be sorted in hierarchical order (e.g. body system class before adverse event term) and are nested in the table. |
rowVarDataLevels |
Data.frame with unique combinations of |
rowVarLab |
Named character vector with
label for the |
rowOrder |
Specify how the rows should be ordered in the final table, either a:
To specify different ordering methods for different |
rowOrderTotalFilterFct |
Function used to filter the data used to order the rows
based on total counts (in case |
rowOrderCatLast |
String with category to be printed in the last
row of each |
rowVarTotalInclude |
Character vector with |
rowVarTotalInSepRow |
Character vector with |
rowVarTotalByVar |
Character vector with a row variable
used to categorize the row total. |
rowVarTotalPerc |
Character vector with row variables by which the total
should be computed for the denominator for the percentage computation.
By default the total is only computed only by column (NULL by default).
If the total should be based on the total number of records per variable,
|
rowInclude0 |
Logical, if TRUE (FALSE by default),
include rows with no records, based on all combinations
of the |
type |
String with type of table:
|
subjectVar |
String, variable of |
dataTotal |
Data.frame used to extract the Total number of subject
per column in column header ('N = [X]').
It should contain the variables specified by |
dataTotalPerc |
Data.frame used to extract the total counts per column
for the computation of the percentage. |
dataTotalRow |
Data.frame used to extract the total count across all
elements of the row
variable, list of such data.frame for each |
dataTotalCol |
Data.frame from which the total across columns is
extracted (in case
If only a subset of the variables is specified in this list,
By default, |
stats |
(optional) Statistic(s) of interest to compute, either:
|
statsVarBy |
String with variable in |
statsExtra |
(optional) Named list with functions for additional custom
statistics to be computed.
For example, to additionally compute the coefficient of variation, this can be set to:
|
statsGeneralLab |
String with general label for statistics, 'Statistic' by default.
Only included if no |
statsPerc |
String with 'base statistical variable' used to compute the percentage, either:
|
filterFct |
(optional) Function taking as input
the summary table with computed statistics and returning a subset
of the summary table.
|
labelVars |
(optional) Named character vector with label for
the row, column variable(s) or variable(s) to summarize. |
byVar |
Variable(s) of |
byVarLab |
String with label for |
checkVarDiffBySubj |
String, 'error' (default), 'warning',
or 'none'.
Should an error, a warning, or nothing be produced
if a continuous variable ( |
An object summaryTable
or list of such objects if
byVar
is specified.
Laure Cougnaud
Convert summary statistics table to flextable
convertSummaryStatisticsTableToFlextable( summaryTable, colHeaderMerge = TRUE, landscape = (style == "presentation"), margin = 1, rowPadBase = 14.4, title = NULL, footer = NULL, style = "report", colorTable = getColorPaletteTable(style = style), fontname = switch(style, report = "Times", presentation = "Tahoma"), fontsize = switch(style, report = 8, presentation = 10), file = NULL, pageDim = NULL, columnsWidth = NULL )
convertSummaryStatisticsTableToFlextable( summaryTable, colHeaderMerge = TRUE, landscape = (style == "presentation"), margin = 1, rowPadBase = 14.4, title = NULL, footer = NULL, style = "report", colorTable = getColorPaletteTable(style = style), fontname = switch(style, report = "Times", presentation = "Tahoma"), fontsize = switch(style, report = 8, presentation = 10), file = NULL, pageDim = NULL, columnsWidth = NULL )
summaryTable |
A |
colHeaderMerge |
(flextable output) Logical, if TRUE (FALSE by default) the column header is merged. |
landscape |
(flextable output) Logical, if TRUE the file is in landscape format. |
margin |
(flextable output) Margin in the document in inches
(1 by default).
This is used to specify the width of the table, from:
[ |
rowPadBase |
(flextable output) Base padding for row (in points), 14.4 by default (corresponds to 0.2 inches) |
title |
Character vector with title(s) for the table.
Set to NULL (by default) if no title should be included.
If multiple are specified, specified for each element of |
footer |
(flextable output) Character vector with footer(s) for the table. Set to NULL (by default) if no footer should be included. |
style |
(flextable output) String with table style, either 'report' or 'presentation'. This parameter affects the fontsize, font family, color of the text and background, and table dimensions of the table. |
colorTable |
(flextable output) Named character vector with color for the table background/body/text/line,
e.g. created with the |
fontname |
(flextable output) String with font name, by default:
'Times' if |
fontsize |
(flextable output) Integer with font size, by default:
8 if |
file |
String with path of the file where the table should be exported.
The file should have the extension: '.html'.
If NULL, the summary table is not exported but only returned as output.
If |
pageDim |
Numeric vector of length 2 with page width and height.
|
columnsWidth |
(expert mode) Column widths of the table. This is only used
for flextable and DT tables. |
flextable
object with summary table
If summaryTable
is a list of summary tables,
returns a list of flextable
.
Laure Cougnaud
Convert flag variable to a format such as only the flagged records are counted in the summary table.
convertVarFlag(x)
convertVarFlag(x)
x |
Character or factor variable with flag variable, should contain elements: 'Y' and 'N', or ” (for missing value). |
Formatted factor variable with levels: 'Y' & 'N'. Empty strings have been converted to NA.
Laure Cougnaud
rowVar
, colVar
and character var
in data
to factorConvert rowVar
, colVar
and character var
in data
to factor
convertVarRowVarColVarToFactor(data, rowVar = NULL, colVar = NULL, var = NULL)
convertVarRowVarColVarToFactor(data, rowVar = NULL, colVar = NULL, var = NULL)
data |
Data.frame with dataset to consider for the summary table. |
rowVar |
Character vector with variable(s) to be included in the rows. If multiple variables are specified, the variables should be sorted in hierarchical order (e.g. body system class before adverse event term) and are nested in the table. |
colVar |
Character vector with variable(s) to be included in columns.
If multiple variables are specified, the variables should
be sorted in hierarchical order,
and are included in multi-columns layout. |
var |
Character vector with variable(s) of |
Updated data
Laure Cougnaud
Convert vector to a bincode of 0/1 based on consecutive values in the vector.
convertVectToBinary(x)
convertVectToBinary(x)
x |
Vector. |
Integer vector of same length than x
.
Laure Cougnaud
x <- c("group1", "group1", "group1", "group2", "group2", "group3", "group4", "group4") convertVectToBinary(x = x)
x <- c("group1", "group1", "group1", "group2", "group2", "group3", "group4", "group4") convertVectToBinary(x = x)
Create a flextable, setting the column names to syntactic names if it is not the case.
createFlextableWithHeader( data, headerDf = NULL, title = NULL, includeRownames = TRUE, colHeaderMerge = TRUE )
createFlextableWithHeader( data, headerDf = NULL, title = NULL, includeRownames = TRUE, colHeaderMerge = TRUE )
data |
Data.frame with data. |
headerDf |
(optional) Data.frame with header.
This should contain the same number of columns than |
title |
Character vector with title(s) for the table. Set to NULL (by default) if no title should be included. |
includeRownames |
Logical, if TRUE (by default)
rownames are included in the |
colHeaderMerge |
(flextable output) Logical, if TRUE (FALSE by default) the column header is merged. |
list with:
'ft': flextable
'colsData': Named vector with original column names, with names set to new syntactic names.
Laure Cougnaud
The coefficient of variation is computed as:
, with:
: standard deviation of
x
: arithmetic mean of
x
cv(x, na.rm = FALSE)
cv(x, na.rm = FALSE)
x |
Numeric vector. |
na.rm |
Logical, should NA value(s) be removed (FALSE by default)? |
Numeric vector of length 1 with coefficient of variation.
Laure Cougnaud
Other stats utility functions:
geomCV()
,
geomMean()
,
geomSD()
,
geomSE()
,
se()
# coefficient of variation of normal distribution tends to 100% cv(rnorm(n = 1000, mean = 1, sd = 1))
# coefficient of variation of normal distribution tends to 100% cv(rnorm(n = 1000, mean = 1, sd = 1))
Export an object
export(...)
export(...)
... |
Extra parameters for the corresponding method. |
export.summaryTable
to export summaryTable
objects.
docx
, pptx
or html
format (interactive table)The use of export
is recommended.exportSummaryStatisticsTable
is retained for
back-compatibility.
## S3 method for class 'summaryTable' export(...) exportSummaryStatisticsTable( summaryTable, rowVar = getAttribute(summaryTable, "rowVar"), rowVarLab = getAttribute(summaryTable, "rowVarLab", default = getLabelVar(rowVar, labelVars = labelVars)), rowVarInSepCol = NULL, rowVarFormat = NULL, rowVarTotalInclude = getAttribute(summaryTable, "rowVarTotalInclude"), rowTotalLab = NULL, rowVarTotalInSepRow = getAttribute(summaryTable, "rowVarTotalInSepRow"), rowAutoMerge = TRUE, colVar = getAttribute(summaryTable, "colVar"), colTotalLab = getAttribute(summaryTable, "colTotalLab", default = "Total"), colHeaderTotalInclude = TRUE, colHeaderMerge = TRUE, statsVar = getAttribute(summaryTable, "statsVar"), statsLayout = getAttribute(summaryTable, "statsLayout", default = ifelse("DT" %in% outputType, "col", "row")), statsValueLab = "StatisticValue", statsLabInclude = NULL, emptyValue = "-", labelVars = NULL, file = NULL, title = NULL, outputType = "flextable", pageDim = NULL, columnsWidth = NULL, landscape = (style == "presentation"), margin = 1, rowPadBase = 14.4, footer = NULL, style = "report", colorTable = getColorPaletteTable(style = style), fontsize = switch(style, report = 8, presentation = 10), fontname = switch(style, report = "Times", presentation = "Tahoma"), vline = "none", hline = "auto", expandVar = NULL, noEscapeVar = NULL, barVar = NULL, ... )
## S3 method for class 'summaryTable' export(...) exportSummaryStatisticsTable( summaryTable, rowVar = getAttribute(summaryTable, "rowVar"), rowVarLab = getAttribute(summaryTable, "rowVarLab", default = getLabelVar(rowVar, labelVars = labelVars)), rowVarInSepCol = NULL, rowVarFormat = NULL, rowVarTotalInclude = getAttribute(summaryTable, "rowVarTotalInclude"), rowTotalLab = NULL, rowVarTotalInSepRow = getAttribute(summaryTable, "rowVarTotalInSepRow"), rowAutoMerge = TRUE, colVar = getAttribute(summaryTable, "colVar"), colTotalLab = getAttribute(summaryTable, "colTotalLab", default = "Total"), colHeaderTotalInclude = TRUE, colHeaderMerge = TRUE, statsVar = getAttribute(summaryTable, "statsVar"), statsLayout = getAttribute(summaryTable, "statsLayout", default = ifelse("DT" %in% outputType, "col", "row")), statsValueLab = "StatisticValue", statsLabInclude = NULL, emptyValue = "-", labelVars = NULL, file = NULL, title = NULL, outputType = "flextable", pageDim = NULL, columnsWidth = NULL, landscape = (style == "presentation"), margin = 1, rowPadBase = 14.4, footer = NULL, style = "report", colorTable = getColorPaletteTable(style = style), fontsize = switch(style, report = 8, presentation = 10), fontname = switch(style, report = "Times", presentation = "Tahoma"), vline = "none", hline = "auto", expandVar = NULL, noEscapeVar = NULL, barVar = NULL, ... )
... |
(DT output) Extra parameters passed to the
|
summaryTable |
A |
rowVar |
Character vector with variable(s) to be included in the rows. If multiple variables are specified, the variables should be sorted in hierarchical order (e.g. body system class before adverse event term) and are nested in the table. |
rowVarLab |
Named character vector with
label for the |
rowVarInSepCol |
Character vector with |
rowVarFormat |
(flextable output) Named list with special formatting for the |
rowVarTotalInclude |
Character vector with |
rowTotalLab |
(flextable output) string with label for the row with total. |
rowVarTotalInSepRow |
Character vector with |
rowAutoMerge |
(flextable output) Logical, if TRUE (by default) automatically merge rows, e.g. in case there is only one sub-category (e.g. categorical variable with only one group) or only one statistic per category. |
colVar |
Character vector with variable(s) to be included in columns.
If multiple variables are specified, the variables should
be sorted in hierarchical order,
and are included in multi-columns layout. |
colTotalLab |
String, label for the total column 'Total' by default. |
colHeaderTotalInclude |
Logical, if TRUE include the total of number of patients
( |
colHeaderMerge |
(flextable output) Logical, if TRUE (FALSE by default) the column header is merged. |
statsVar |
Character vector with columns of |
statsLayout |
String with layout for the statistics names (in case more than one statistic is included), among:
|
statsValueLab |
String with label for the statistic value,
'StatisticValue' by default. |
statsLabInclude |
Logical, if TRUE include the statistic label
in the table. |
emptyValue |
String with placeholder used to fill the table for missing values, '-' by default. This value is typically used e.g. if not all statistics are computed for all specified row/col/var variables. |
labelVars |
(optional) Named character vector with label for
the row, column variable(s) or variable(s) to summarize. |
file |
(Optional) Name of the file the table should be exported to, either:
If NULL (by default), the summary table is not exported but only returned as output.
If |
title |
Character vector with title(s) for the table.
Set to NULL (by default) if no title should be included.
If multiple are specified, specified for each element of |
outputType |
String with output type:
|
pageDim |
Numeric vector of length 2 with page width and height.
|
columnsWidth |
(expert mode) Column widths of the table. This is only used
for flextable and DT tables. |
landscape |
(flextable output) Logical, if TRUE the file is in landscape format. |
margin |
(flextable output) Margin in the document in inches
(1 by default).
This is used to specify the width of the table, from:
[ |
rowPadBase |
(flextable output) Base padding for row (in points), 14.4 by default (corresponds to 0.2 inches) |
footer |
(flextable output) Character vector with footer(s) for the table. Set to NULL (by default) if no footer should be included. |
style |
(flextable output) String with table style, either 'report' or 'presentation'. This parameter affects the fontsize, font family, color of the text and background, and table dimensions of the table. |
colorTable |
(flextable output) Named character vector with color for the table background/body/text/line,
e.g. created with the |
fontsize |
(flextable output) Integer with font size, by default:
8 if |
fontname |
(flextable output) String with font name, by default:
'Times' if |
vline |
(flextable output) String mentioning how vertical lines should be included in the body of the table, either:
|
hline |
(flextable output) String mentioning how horizontal lines should be included in the body of the table, either:
|
expandVar |
(DT output) Character vector with variables of the summary table which should be expanded in the data. |
noEscapeVar |
(DT output) Character vector with variables of |
barVar |
(DT output) Character vector with variables of |
Depending on the outputType
:
'data.frame-base': input summary table in a long format with all computed statistics
'data.frame': summary table in a wide format (
different columns for each colVar
), with specified labels
'flextable' (by default): flextable
object with summary table
'DT': datatable
object with summary table
If multiple outputType
are specified, a list of those objects, named
by outputType
.
If byVar
is specified, each object consists of a list of tables,
one for each element in byVar
.
export(summaryTable)
: export summaryTable
object
Laure Cougnaud
Export flextable to docx file
exportFlextableToDocx( object, file, landscape = FALSE, breaksAfter = if (!inherits(object, "flextable")) seq_along(object) else 1 )
exportFlextableToDocx( object, file, landscape = FALSE, breaksAfter = if (!inherits(object, "flextable")) seq_along(object) else 1 )
object |
|
file |
String with path of the file where the table should be exported.
The file should have the extension: '.html'.
If NULL, the summary table is not exported but only returned as output.
If |
landscape |
(flextable output) Logical, if TRUE the file is in landscape format. |
breaksAfter |
In case |
no returned value, the object
is exported to a docx file.
Laure Cougnaud
Export summary table to an interactive DT table, e.g. to be exported into an html document.
exportSummaryStatisticsTableToDT( summaryTable, rowVar = getAttribute(summaryTable, "rowVar"), rowVarLab = getAttribute(summaryTable, "rowVarLab", default = getLabelVar(rowVar, labelVars = labelVars)), rowVarInSepCol = NULL, statsVar = getAttribute(summaryTable, "statsVar"), statsLayout = getAttribute(summaryTable, "statsLayout", default = "col"), statsValueLab = "StatisticValue", title = NULL, expandVar = NULL, noEscapeVar = NULL, barVar = NULL, pageDim = NULL, labelVars = NULL, file = NULL, ... )
exportSummaryStatisticsTableToDT( summaryTable, rowVar = getAttribute(summaryTable, "rowVar"), rowVarLab = getAttribute(summaryTable, "rowVarLab", default = getLabelVar(rowVar, labelVars = labelVars)), rowVarInSepCol = NULL, statsVar = getAttribute(summaryTable, "statsVar"), statsLayout = getAttribute(summaryTable, "statsLayout", default = "col"), statsValueLab = "StatisticValue", title = NULL, expandVar = NULL, noEscapeVar = NULL, barVar = NULL, pageDim = NULL, labelVars = NULL, file = NULL, ... )
summaryTable |
Summary table as provided by the
|
rowVar |
Character vector with variable(s) to be included in the rows. If multiple variables are specified, the variables should be sorted in hierarchical order (e.g. body system class before adverse event term) and are nested in the table. |
rowVarLab |
Named character vector with
label for the |
rowVarInSepCol |
Character vector with |
statsVar |
Character vector with columns of |
statsLayout |
String with layout for the statistics names (in case more than one statistic is included), among:
|
statsValueLab |
String with label for the statistic value,
'StatisticValue' by default. |
title |
Character vector with title(s) for the table.
Set to NULL (by default) if no title should be included.
If multiple are specified, specified for each element of |
expandVar |
(DT output) Character vector with variables of the summary table which should be expanded in the data. |
noEscapeVar |
(DT output) Character vector with variables of |
barVar |
(DT output) Character vector with variables of |
pageDim |
Numeric vector of length 2 with page width and height.
|
labelVars |
(optional) Named character vector with label for
the row, column variable(s) or variable(s) to summarize. |
file |
String with path of the file where the table should be exported.
The file should have the extension: '.docx'.
If NULL, the summary table is not exported but only returned as output.
If |
... |
(DT output) Extra parameters passed to the
|
A datatable
object.
Laure Cougnaud
Export summary table to a flextable object, e.g. to be exported in Word or PowerPoint.
exportSummaryStatisticsTableToFlextable( summaryTable, rowVar = getAttribute(summaryTable, "rowVar"), rowVarInSepCol = NULL, rowVarTotalInclude = getAttribute(summaryTable, "rowVarTotalInclude"), statsLayout = getAttribute(summaryTable, "statsLayout", default = "row"), statsVar = getAttribute(summaryTable, "statsVar"), statsLabInclude = getAttribute(summaryTable, "statsLabInclude", default = length(statsVar) > 1), rowVarLab = getAttribute(summaryTable, "rowVarLab", default = getLabelVar(rowVar, labelVars = labelVars)), rowVarTotalInSepRow = NULL, vline = c("none", "auto"), hline = c("auto", "none"), rowAutoMerge = TRUE, rowVarFormat = NULL, rowTotalLab = NULL, colHeaderMerge = TRUE, landscape = (style == "presentation"), margin = 1, rowPadBase = 14.4, title = NULL, footer = NULL, style = "report", colorTable = getColorPaletteTable(style = style), fontname = switch(style, report = "Times", presentation = "Tahoma"), fontsize = switch(style, report = 8, presentation = 10), file = NULL, pageDim = NULL, columnsWidth = NULL, labelVars = NULL )
exportSummaryStatisticsTableToFlextable( summaryTable, rowVar = getAttribute(summaryTable, "rowVar"), rowVarInSepCol = NULL, rowVarTotalInclude = getAttribute(summaryTable, "rowVarTotalInclude"), statsLayout = getAttribute(summaryTable, "statsLayout", default = "row"), statsVar = getAttribute(summaryTable, "statsVar"), statsLabInclude = getAttribute(summaryTable, "statsLabInclude", default = length(statsVar) > 1), rowVarLab = getAttribute(summaryTable, "rowVarLab", default = getLabelVar(rowVar, labelVars = labelVars)), rowVarTotalInSepRow = NULL, vline = c("none", "auto"), hline = c("auto", "none"), rowAutoMerge = TRUE, rowVarFormat = NULL, rowTotalLab = NULL, colHeaderMerge = TRUE, landscape = (style == "presentation"), margin = 1, rowPadBase = 14.4, title = NULL, footer = NULL, style = "report", colorTable = getColorPaletteTable(style = style), fontname = switch(style, report = "Times", presentation = "Tahoma"), fontsize = switch(style, report = 8, presentation = 10), file = NULL, pageDim = NULL, columnsWidth = NULL, labelVars = NULL )
summaryTable |
Summary table as provided by the
|
rowVar |
Character vector with variable(s) to be included in the rows. If multiple variables are specified, the variables should be sorted in hierarchical order (e.g. body system class before adverse event term) and are nested in the table. |
rowVarInSepCol |
Character vector with |
rowVarTotalInclude |
Character vector with |
statsLayout |
String with layout for the statistics names (in case more than one statistic is included), among:
|
statsVar |
Character vector with columns of |
statsLabInclude |
Logical, if TRUE include the statistic label
in the table. |
rowVarLab |
Named character vector with
label for the |
rowVarTotalInSepRow |
Character vector with |
vline |
(flextable output) String mentioning how vertical lines should be included in the body of the table, either:
|
hline |
(flextable output) String mentioning how horizontal lines should be included in the body of the table, either:
|
rowAutoMerge |
(flextable output) Logical, if TRUE (by default) automatically merge rows, e.g. in case there is only one sub-category (e.g. categorical variable with only one group) or only one statistic per category. |
rowVarFormat |
(flextable output) Named list with special formatting for the |
rowTotalLab |
(flextable output) string with label for the row with total. |
colHeaderMerge |
(flextable output) Logical, if TRUE (FALSE by default) the column header is merged. |
landscape |
(flextable output) Logical, if TRUE the file is in landscape format. |
margin |
(flextable output) Margin in the document in inches
(1 by default).
This is used to specify the width of the table, from:
[ |
rowPadBase |
(flextable output) Base padding for row (in points), 14.4 by default (corresponds to 0.2 inches) |
title |
Character vector with title(s) for the table.
Set to NULL (by default) if no title should be included.
If multiple are specified, specified for each element of |
footer |
(flextable output) Character vector with footer(s) for the table. Set to NULL (by default) if no footer should be included. |
style |
(flextable output) String with table style, either 'report' or 'presentation'. This parameter affects the fontsize, font family, color of the text and background, and table dimensions of the table. |
colorTable |
(flextable output) Named character vector with color for the table background/body/text/line,
e.g. created with the |
fontname |
(flextable output) String with font name, by default:
'Times' if |
fontsize |
(flextable output) Integer with font size, by default:
8 if |
file |
String with path of the file where the table should be exported.
The file should have the extension: '.html'.
If NULL, the summary table is not exported but only returned as output.
If |
pageDim |
Numeric vector of length 2 with page width and height.
|
columnsWidth |
(expert mode) Column widths of the table. This is only used
for flextable and DT tables. |
labelVars |
(optional) Named character vector with label for
the row, column variable(s) or variable(s) to summarize. |
flextable
object with summary table
If summaryTable
is a list of summary tables,
returns a list of flextable
.
Laure Cougnaud
The following rules are used:
percentage = 0%: '0'
0% < percentage < 0.1%: '<0.1'
99.9% < percentage < 100%: '>99.9'
percentage = 100%: '100'
missing value (NA) (class without valid data): '-'
other: 'x.x' (1 decimal)
formatPercentage(x, nDec = 1)
formatPercentage(x, nDec = 1)
x |
Numeric vector with percentage(s) |
nDec |
Integer of length 1, number of decimals used to round the percentage, 1 by default. |
String with formatted percentage
Laure Cougnaud
Other decimals:
getMaxNDecimals()
,
getMaxNDecimalsData()
,
getNDecimals()
,
getNDecimalsData()
xPerc <- c(NA, 0, 100, 99.95, 0.012, 34.768) formatPercentage(x = xPerc)
xPerc <- c(NA, 0, 100, 99.95, 0.012, 34.768) formatPercentage(x = xPerc)
Format summary statistics table for export
formatSummaryStatisticsTable( summaryTable, rowVar = getAttribute(summaryTable, "rowVar"), colVar = getAttribute(summaryTable, "colVar"), colTotalLab = getAttribute(summaryTable, "colTotalLab", default = "Total"), colHeaderTotalInclude = TRUE, statsVar = getAttribute(summaryTable, "statsVar"), statsLabInclude = NULL, statsLayout = "row", statsValueLab = "StatisticValue", emptyValue = "-" )
formatSummaryStatisticsTable( summaryTable, rowVar = getAttribute(summaryTable, "rowVar"), colVar = getAttribute(summaryTable, "colVar"), colTotalLab = getAttribute(summaryTable, "colTotalLab", default = "Total"), colHeaderTotalInclude = TRUE, statsVar = getAttribute(summaryTable, "statsVar"), statsLabInclude = NULL, statsLayout = "row", statsValueLab = "StatisticValue", emptyValue = "-" )
summaryTable |
A |
rowVar |
Character vector with variable(s) to be included in the rows. If multiple variables are specified, the variables should be sorted in hierarchical order (e.g. body system class before adverse event term) and are nested in the table. |
colVar |
Character vector with variable(s) to be included in columns.
If multiple variables are specified, the variables should
be sorted in hierarchical order,
and are included in multi-columns layout. |
colTotalLab |
String, label for the total column 'Total' by default. |
colHeaderTotalInclude |
Logical, if TRUE include the total of number of patients
( |
statsVar |
Character vector with columns of |
statsLabInclude |
Logical, if TRUE include the statistic label
in the table. |
statsLayout |
String with layout for the statistics names (in case more than one statistic is included), among:
|
statsValueLab |
String with label for the statistic value,
'StatisticValue' by default. |
emptyValue |
String with placeholder used to fill the table for missing values, '-' by default. This value is typically used e.g. if not all statistics are computed for all specified row/col/var variables. |
summaryTable reformatted to wide format
Laure Cougnaud
flextable
Merge nested rows of a summary table
for a format compatible with flextable
formatSummaryStatisticsTableFlextable( summaryTable, rowVar = getAttribute(summaryTable, "rowVar"), rowVarInSepCol = NULL, rowVarTotalInclude = getAttribute(summaryTable, "rowVarTotalInclude"), statsLayout = "row", statsVar = getAttribute(summaryTable, "statsVar"), statsLabInclude = getAttribute(summaryTable, "statsLabInclude", default = length(statsVar) > 1), rowVarLab = getAttribute(summaryTable, "rowVarLab", default = getLabelVar(rowVar, labelVars = labelVars)), rowVarTotalInSepRow = NULL, vline = c("none", "auto"), hline = c("none", "auto"), rowAutoMerge = TRUE, rowVarFormat = NULL, rowTotalLab = NULL, labelVars = NULL )
formatSummaryStatisticsTableFlextable( summaryTable, rowVar = getAttribute(summaryTable, "rowVar"), rowVarInSepCol = NULL, rowVarTotalInclude = getAttribute(summaryTable, "rowVarTotalInclude"), statsLayout = "row", statsVar = getAttribute(summaryTable, "statsVar"), statsLabInclude = getAttribute(summaryTable, "statsLabInclude", default = length(statsVar) > 1), rowVarLab = getAttribute(summaryTable, "rowVarLab", default = getLabelVar(rowVar, labelVars = labelVars)), rowVarTotalInSepRow = NULL, vline = c("none", "auto"), hline = c("none", "auto"), rowAutoMerge = TRUE, rowVarFormat = NULL, rowTotalLab = NULL, labelVars = NULL )
summaryTable |
A |
rowVar |
Character vector with variable(s) to be included in the rows. If multiple variables are specified, the variables should be sorted in hierarchical order (e.g. body system class before adverse event term) and are nested in the table. |
rowVarInSepCol |
Character vector with |
rowVarTotalInclude |
Character vector with |
statsLayout |
String with layout for the statistics names (in case more than one statistic is included), among:
|
statsVar |
Character vector with columns of |
statsLabInclude |
Logical, if TRUE include the statistic label
in the table. |
rowVarLab |
Named character vector with
label for the |
rowVarTotalInSepRow |
Character vector with |
vline |
(flextable output) String mentioning how vertical lines should be included in the body of the table, either:
|
hline |
(flextable output) String mentioning how horizontal lines should be included in the body of the table, either:
|
rowAutoMerge |
(flextable output) Logical, if TRUE (by default) automatically merge rows, e.g. in case there is only one sub-category (e.g. categorical variable with only one group) or only one statistic per category. |
rowVarFormat |
(flextable output) Named list with special formatting for the |
rowTotalLab |
(flextable output) string with label for the row with total. |
labelVars |
(optional) Named character vector with label for
the row, column variable(s) or variable(s) to summarize. |
summaryTable reformatted in long format, with extra attributes:
'header': data.frame with header for each column
'padParams': list of list of parameters to be passed to the
padding
function
'rowVar': column of output with row variable
'rowVarInSepCol': column(s) of output with row variable in separated column(s)
'vlineParams' and 'hlineParams': list of list with correspondingly parameters for vertical and horizontal lines
'vline': vline
parameter
'formatParams': list of list with special formatting for the table,
currently only used if rowVarFormat
if specified.
If summaryTable
is a list of summary tables,
returns a list of corresponding summary tables in long format.
Laure Cougnaud
The geometric coefficient of variation is computed as:
, with:
log: natural logarithm
: standard deviation
geomCV(x, na.rm = FALSE)
geomCV(x, na.rm = FALSE)
x |
Numeric vector. |
na.rm |
Logical, should NA value(s) be removed (FALSE by default)? |
Numeric vector of length 1 with geometric coefficient of variation.
Laure Cougnaud
Other stats utility functions:
cv()
,
geomMean()
,
geomSD()
,
geomSE()
,
se()
# Geometric coefficient of variation of a sample from a log normal distribution: geomCV(rlnorm(n = 1000, meanlog = 0, sdlog = 1))
# Geometric coefficient of variation of a sample from a log normal distribution: geomCV(rlnorm(n = 1000, meanlog = 0, sdlog = 1))
The geometric mean is computed as:
, with:
log: natural logarithm
: arithmetic mean of log(x)
geomMean(x, na.rm = FALSE)
geomMean(x, na.rm = FALSE)
x |
Numeric vector. |
na.rm |
Logical, should NA value(s) be removed (FALSE by default)? |
Numeric vector of length 1 with geometric mean.
Laure Cougnaud
Other stats utility functions:
cv()
,
geomCV()
,
geomSD()
,
geomSE()
,
se()
# geometric mean of a big sample from log normal distribution # tends to the mean of the distribution: geomMean(rlnorm(n = 1000, meanlog = 0, sdlog = 1))
# geometric mean of a big sample from log normal distribution # tends to the mean of the distribution: geomMean(rlnorm(n = 1000, meanlog = 0, sdlog = 1))
The geometric standard deviation is computed as:
, with:
log: natural logarithm
: standard deviation
geomSD(x, na.rm = FALSE)
geomSD(x, na.rm = FALSE)
x |
Numeric vector. |
na.rm |
Logical, should NA value(s) be removed (FALSE by default)? |
Numeric vector of length 1 with geometric mean.
Laure Cougnaud
Other stats utility functions:
cv()
,
geomCV()
,
geomMean()
,
geomSE()
,
se()
# geometric standard deviation of a sample from a log normal distribution: geomSD(rlnorm(n = 1000, meanlog = 0, sdlog = 1))
# geometric standard deviation of a sample from a log normal distribution: geomSD(rlnorm(n = 1000, meanlog = 0, sdlog = 1))
The geometric standard error of the mean is computed as:
, with:
log: natural logarithm
: standard error of the mean, as computed with
se
geomSE(x, na.rm = FALSE)
geomSE(x, na.rm = FALSE)
x |
Numeric vector. |
na.rm |
Logical, should NA value(s) be removed (FALSE by default)? |
Numeric vector of length 1 with geometric standard error of the mean.
Laure Cougnaud
Other stats utility functions:
cv()
,
geomCV()
,
geomMean()
,
geomSD()
,
se()
# Geometric standard error of the mean of a sample from a log normal distribution: geomSE(rlnorm(n = 1000, meanlog = 0, sdlog = 1))
# Geometric standard error of the mean of a sample from a log normal distribution: geomSE(rlnorm(n = 1000, meanlog = 0, sdlog = 1))
This function gets the color palettes for the tables specified as global options.
getColorPaletteTable(style = c("report", "presentation"))
getColorPaletteTable(style = c("report", "presentation"))
style |
String with style of report. Either 'report' or 'presentation'. By default, the style is 'report'. |
By default, the function returns the palette of the package. The user can specify a custom palette by setting the global options.
A named vector with hex colors.
# report style (the default) getColorPaletteTable() # presentation style getColorPaletteTable(style = "presentation") # custom palette customColorTable <- c('header' = "#FFFFFF",'headerBackground' = "#3F4788FF", 'body' = "#000000", 'bodyBackground1' = "#D9D9D9", 'bodyBackground2' = "#D9D9D9", 'footer' = "#000000", 'footerBackground' = "#FFFFFF",'line' = "#FFFFFF") options(inTextSummaryTable.colors.table.presentation = customColorTable) getColorPaletteTable("presentation")
# report style (the default) getColorPaletteTable() # presentation style getColorPaletteTable(style = "presentation") # custom palette customColorTable <- c('header' = "#FFFFFF",'headerBackground' = "#3F4788FF", 'body' = "#000000", 'bodyBackground1' = "#D9D9D9", 'bodyBackground2' = "#D9D9D9", 'footer' = "#000000", 'footerBackground' = "#FFFFFF",'line' = "#FFFFFF") options(inTextSummaryTable.colors.table.presentation = customColorTable) getColorPaletteTable("presentation")
Report is in A4 and presentation dimensions extracted from PowerPoint. The returned dimensions are the page dimensions without the margins.
getDimPage( type = c("width", "height"), landscape = (style == "presentation"), margin = 1, pageDim = NULL, style = "report" )
getDimPage( type = c("width", "height"), landscape = (style == "presentation"), margin = 1, pageDim = NULL, style = "report" )
type |
Character vector with dimension of interest, among:
'width', 'height', multiple are possible.
By default: |
landscape |
Logical, if TRUE the table is presented in landscape
format. |
margin |
Margin in the document in inches, 1 by default. |
pageDim |
(optional) Numeric vector of length 2 with page width and height in inches in portrait format, in case page dimensions differ from the default implemented report/presentation. These dimensions should include the margins. |
style |
String with table style, either 'report' (by default, a4 format) or 'presentation' |
numeric vector with dimension of interest,
in the same order as specified via the type
parameter.
Laure Cougnaud
## get part of the page available for content # report A4 portrait format: getDimPage(type = "width") getDimPage(type = "height") # report A4 landscape format: getDimPage(type = "width", landscape = TRUE) getDimPage(type = "height", landscape = TRUE) # Note that the layout is by default set to 'landscape' getDimPage(type = "width", style = "presentation") getDimPage(type = "height", style = "presentation") # custom dimensions: A3 format getDimPage(type = "width", pageDim = c(11.7, 16.5)) # increase margin getDimPage(type = "width", margin = 1.5) # get both dimensions at once getDimPage(type = c("width", "height")) # get dimensions of the full page (including margins) getDimPage(type = c("width", "height"), style = "report", margin = 0) getDimPage(type = c("width", "height"), style = "presentation", margin = 0)
## get part of the page available for content # report A4 portrait format: getDimPage(type = "width") getDimPage(type = "height") # report A4 landscape format: getDimPage(type = "width", landscape = TRUE) getDimPage(type = "height", landscape = TRUE) # Note that the layout is by default set to 'landscape' getDimPage(type = "width", style = "presentation") getDimPage(type = "height", style = "presentation") # custom dimensions: A3 format getDimPage(type = "width", pageDim = c(11.7, 16.5)) # increase margin getDimPage(type = "width", margin = 1.5) # get both dimensions at once getDimPage(type = c("width", "height")) # get dimensions of the full page (including margins) getDimPage(type = c("width", "height"), style = "report", margin = 0) getDimPage(type = c("width", "height"), style = "presentation", margin = 0)
Flextable version >= 0.4.7 and pandoc >= 2.4 is required to included such table in a Rmarkdown document.
getListing( data, ft, border = TRUE, highlight = integer(), bgVar = NULL, fontname = switch(style, report = "Times", presentation = "Tahoma"), fontsize = switch(style, report = 8, presentation = 10), landscape = (style == "presentation"), style = "report", margin = 1, adjustWidth = TRUE, colorTable = getColorPaletteTable(style = style), align = TRUE, title = NULL, pageDim = NULL, includeRownames = TRUE )
getListing( data, ft, border = TRUE, highlight = integer(), bgVar = NULL, fontname = switch(style, report = "Times", presentation = "Tahoma"), fontsize = switch(style, report = 8, presentation = 10), landscape = (style == "presentation"), style = "report", margin = 1, adjustWidth = TRUE, colorTable = getColorPaletteTable(style = style), align = TRUE, title = NULL, pageDim = NULL, includeRownames = TRUE )
data |
data.frame with data used in table. |
ft |
Corresponding |
border |
Logical, if TRUE add a border. |
highlight |
Integer vector with index(ices) of column(s) to highlight
(only applies for
|
bgVar |
String with the column of the |
fontname |
String with font name, 'Times' by default. |
fontsize |
Integer with font size, 8 by default. |
landscape |
Logical, if TRUE the table is presented in landscape
format. |
style |
String with table style, either 'report' (by default, a4 format) or 'presentation' |
margin |
Margin in the document in inches, 1 by default. |
adjustWidth |
Logical, if TRUE adjust column widths,
to comply to specification of |
colorTable |
Named character vector with color for the table,
see output of |
align |
Logical, if TRUE (by default), default alignment is set ('center' in all table). |
title |
Character vector with title(s) for the table.
Set to NULL (by default) if no title should be included.
Only available if |
pageDim |
(optional) Numeric vector of length 2 with page width and height in inches in portrait format, in case page dimensions differ from the default implemented report/presentation. These dimensions should include the margins. |
includeRownames |
Logical, if TRUE (by default)
rownames are included in the |
flextable
with style.
# style: report or presentation getListing(data = head(mtcars), style = "report") getListing(data = head(mtcars), style = "presentation") # remove rownames (included by default) getListing(data = head(mtcars), style = "presentation", includeRownames = FALSE) # highlight: # all columns getListing(data = head(mtcars), style = "presentation", highlight = seq_along(mtcars)) # rownames getListing(data = head(mtcars), style = "presentation", highlight = 0) # specific columns getListing(data = head(mtcars), style = "presentation", highlight = c(2, 4))
# style: report or presentation getListing(data = head(mtcars), style = "report") getListing(data = head(mtcars), style = "presentation") # remove rownames (included by default) getListing(data = head(mtcars), style = "presentation", includeRownames = FALSE) # highlight: # all columns getListing(data = head(mtcars), style = "presentation", highlight = seq_along(mtcars)) # rownames getListing(data = head(mtcars), style = "presentation", highlight = 0) # specific columns getListing(data = head(mtcars), style = "presentation", highlight = c(2, 4))
The function getNDecimals
) extracts the number
of decimals in a specific variable.
getMaxNDecimals(x, ...)
getMaxNDecimals(x, ...)
x |
Numeric vector. |
... |
Any parameters for the |
Integer with maximum number of decimals in a character vector.
Laure Cougnaud
Other decimals:
formatPercentage()
,
getMaxNDecimalsData()
,
getNDecimals()
,
getNDecimalsData()
x <- c(0.99, 5.679, 50.45, 1450) # extract max number of decimals based on data: getMaxNDecimals(x, useRule = FALSE, useData = TRUE) # extract max number of decimals based on pre-defined rule: getMaxNDecimals(x, useRule = TRUE, useData = FALSE) # extract max number of decimals based on both rules # minimum of both is used (by default) getMaxNDecimals(x, useRule = TRUE, useData = TRUE)
x <- c(0.99, 5.679, 50.45, 1450) # extract max number of decimals based on data: getMaxNDecimals(x, useRule = FALSE, useData = TRUE) # extract max number of decimals based on pre-defined rule: getMaxNDecimals(x, useRule = TRUE, useData = FALSE) # extract max number of decimals based on both rules # minimum of both is used (by default) getMaxNDecimals(x, useRule = TRUE, useData = TRUE)
getNDecimalsData
)Get maximum number of decimals in a variable based on the data
(getNDecimalsData
)
getMaxNDecimalsData(x)
getMaxNDecimalsData(x)
x |
Numeric vector. |
Integer with maximum number of decimals in a character vector.
Laure Cougnaud x <- c(0.99, 5.679, 50.45, 1450) # extract max number of decimals based on data: getMaxNDecimalsData(x)
Other decimals:
formatPercentage()
,
getMaxNDecimals()
,
getNDecimals()
,
getNDecimalsData()
The number of decimals is extracted either:
from specific implemented rule :
see getNDecimalsRule
for further details
from the data itself:
see getNDecimalsData
for further details
both criterias: in this case the minimum of the number of decimals for both criterias is used
getNDecimals(x, useRule = TRUE, rule = "1", useData = TRUE)
getNDecimals(x, useRule = TRUE, rule = "1", useData = TRUE)
x |
Numeric vector. |
useRule |
Logical (TRUE by default), should the |
rule |
Character vector with rule to use to derive the number of parameters. Currently only: '1' is implemented.
|
useData |
Logical (TRUE by default), should the number of decimals
be extracted based on the input data |
Numeric vector of same length than x
with the number of decimals.
Laure Cougnaud
Other decimals:
formatPercentage()
,
getMaxNDecimals()
,
getMaxNDecimalsData()
,
getNDecimalsData()
x <- c(0.99, 5.679, 50.45, 1450) # extract number of decimals based on data: getNDecimals(x, useRule = FALSE, useData = TRUE) # extract number of decimals based on pre-defined rule: getNDecimals(x, useRule = TRUE, useData = FALSE) # extract number of decimals based on both rules # minimum of both is used (by default) getNDecimals(x, useRule = TRUE, useData = TRUE)
x <- c(0.99, 5.679, 50.45, 1450) # extract number of decimals based on data: getNDecimals(x, useRule = FALSE, useData = TRUE) # extract number of decimals based on pre-defined rule: getNDecimals(x, useRule = TRUE, useData = FALSE) # extract number of decimals based on both rules # minimum of both is used (by default) getNDecimals(x, useRule = TRUE, useData = TRUE)
Get number of decimals based on the data in a numeric vector. Note: NA is returned if the element is missing (NA).
getNDecimalsData(x)
getNDecimalsData(x)
x |
Numeric vector. |
Numeric vector of same length than x
with the number of decimals.
Laure Cougnaud
Other decimals:
formatPercentage()
,
getMaxNDecimals()
,
getMaxNDecimalsData()
,
getNDecimals()
x <- c(0.99, 5.679, 50.45, 1450) getNDecimalsData(x)
x <- c(0.99, 5.679, 50.45, 1450) getNDecimalsData(x)
Note: NA is returned if the element is missing (NA).
getNDecimalsRule(x, rule = c("1"))
getNDecimalsRule(x, rule = c("1"))
x |
Numeric vector. |
rule |
Character vector with rule to use to derive the number of parameters. Currently only: '1' is implemented.
|
Numeric vector of same length than x
with the number of decimals.
Laure Cougnaud
x <- c(0.99, 5.679, 50.45, 1450) getNDecimalsRule(x = x)
x <- c(0.99, 5.679, 50.45, 1450) getNDecimalsRule(x = x)
Get position(s) (start, end) of a pattern in a string.
getPatternPosition(x, startPattern, endPattern = "\\}", format)
getPatternPosition(x, startPattern, endPattern = "\\}", format)
x |
String. |
startPattern |
String with start pattern. |
endPattern |
String with end pattern. |
format |
String with type of formatting |
Matrix with columns: 'start' and 'end' with
start and end position(x) of the pattern, 'format' with
the format
and 'pattern' with the regex pattern for the full match.
NULL if no match.
Laure Cougnaud
This set of statistics can be passed directly to the stats
parameter
of the of the package functions.
getStats( type = "summary", includeName = TRUE, x = NULL, nDecCont = getMaxNDecimals, nDecN = 0, nDecm = nDecN, formatPercentage = inTextSummaryTable::formatPercentage )
getStats( type = "summary", includeName = TRUE, x = NULL, nDecCont = getMaxNDecimals, nDecN = 0, nDecm = nDecN, formatPercentage = inTextSummaryTable::formatPercentage )
type |
Character vector with type of statistics (multiple are possible).
Available statistics are specified in the section 'Formatted statistics' and
formatting in 'Statistics formatting' in
|
includeName |
Logical, should the statistics name be included (TRUE by default)?
This is applied for the statistic names used in each for the set defined in |
x |
(optional, recommended for continuous variable) Numeric vector
for which the statistics should be computed on. |
nDecCont |
Integer with base number of decimals
for continuous variable, or function returning this number based on |
nDecN , nDecm
|
Integer with number of decimals for number of subjects/records (0 by default). |
formatPercentage |
Function used to format the percentages
(see |
Expression (or call object) containing
function to extract requested summary statistics.
If multiple type
are specified, they are combined to a list.
Names of the list will be typically used to name the statistic
in the summary table.
Laure Cougnaud
## default set of statistics are available for: # for count table: getStats("count") getStats("n (%)") getStats("n") getStats("%") getStats("m") getStats("%m") getStats("m (%)") # for continuous variable: getStats("summary") getStats("mean (se)") getStats("mean (sd)") getStats("median (range)") getStats("median\n(range)") getStats(c("Mean", "SE")) ## to not include statistic name in the table getStats("median\n(range)", includeName = FALSE) getStats(c("summary", "median\n(range)"), includeName = FALSE) ## to extract the number of decimals based on a continuous variable (see ?getMaxNDecimals) exampleData <- data.frame( USUBJID = 1 : 4, WEIGHT = c(67, 78, 83, 61), SEX = c("F", "M", "M", "F"), stringsAsFactors = FALSE ) getStats(type = c('median (range)', 'mean (se)'), x = exampleData$WEIGHT) # compare with when 'x' is not specified: getStats(type = c('median (range)', 'mean (se)')) ## custom function to format the percentages: getStats(type = "count", formatPercentage = function(x) round(x, 2))
## default set of statistics are available for: # for count table: getStats("count") getStats("n (%)") getStats("n") getStats("%") getStats("m") getStats("%m") getStats("m (%)") # for continuous variable: getStats("summary") getStats("mean (se)") getStats("mean (sd)") getStats("median (range)") getStats("median\n(range)") getStats(c("Mean", "SE")) ## to not include statistic name in the table getStats("median\n(range)", includeName = FALSE) getStats(c("summary", "median\n(range)"), includeName = FALSE) ## to extract the number of decimals based on a continuous variable (see ?getMaxNDecimals) exampleData <- data.frame( USUBJID = 1 : 4, WEIGHT = c(67, 78, 83, 61), SEX = c("F", "M", "M", "F"), stringsAsFactors = FALSE ) getStats(type = c('median (range)', 'mean (se)'), x = exampleData$WEIGHT) # compare with when 'x' is not specified: getStats(type = c('median (range)', 'mean (se)')) ## custom function to format the percentages: getStats(type = "count", formatPercentage = function(x) round(x, 2))
This set of statistics can be passed directly to the stats
parameter
of the package functions.
By default, statistics are extracted based on the variable(s) type
and formatted with the default rules implemented in the package.
getStatsData( data, var = NULL, type = "default", extra = NULL, args = NULL, ... )
getStatsData( data, var = NULL, type = "default", extra = NULL, args = NULL, ... )
data |
Data.frame with dataset to consider for the summary table. |
var |
(optional, recommended for continuous variable)
Character vector with variable(s) of data, to
compute statistics on. |
type |
Character vector with type of statistics to extract, among:
To specify statistics for a continuous (numeric) or categorical variable separately, this vector can be named with: 'cont' or 'cat' respectively (elements not named are used for both continuous and categorical variables). |
extra |
List with extra statistics to include, or function to apply on each
|
args |
(optional) Named list with extra arguments for
|
... |
Extra parameters passed to the |
List with statistics to compute, named by var
Laure Cougnaud
# default set of statistics (depending if the variable is continuous or categorical) exampleData <- data.frame( USUBJID = 1 : 4, WEIGHT = c(67, 78, 83, 61), SEX = c("F", "M", "M", "F"), stringsAsFactors = FALSE ) getStatsData(data = exampleData, var = c("WEIGHT", "SEX")) # all set of statistics (depending if the variable is continuous or categorical) getStatsData(data = exampleData, var = c("WEIGHT", "SEX"), type = "all") # custom set of statistics for all variables getStatsData(data = exampleData, var = c("WEIGHT", "SEX"), type = c("n", "%")) # custom set of statistics, depending on the type of the variable getStatsData(data = exampleData, var = c("WEIGHT", "SEX"), type = c(cont = "median (range)", cont = "mean (se)", cat = "n (%)"), args = list(cat = list(includeName = FALSE)) )
# default set of statistics (depending if the variable is continuous or categorical) exampleData <- data.frame( USUBJID = 1 : 4, WEIGHT = c(67, 78, 83, 61), SEX = c("F", "M", "M", "F"), stringsAsFactors = FALSE ) getStatsData(data = exampleData, var = c("WEIGHT", "SEX")) # all set of statistics (depending if the variable is continuous or categorical) getStatsData(data = exampleData, var = c("WEIGHT", "SEX"), type = "all") # custom set of statistics for all variables getStatsData(data = exampleData, var = c("WEIGHT", "SEX"), type = c("n", "%")) # custom set of statistics, depending on the type of the variable getStatsData(data = exampleData, var = c("WEIGHT", "SEX"), type = c(cont = "median (range)", cont = "mean (se)", cat = "n (%)"), args = list(cat = list(includeName = FALSE)) )
Get summary statistics table
getSummaryStatisticsTable( data, var = NULL, varFlag = NULL, varLab = NULL, varLabInclude = length(var) > 1, varInclude0 = FALSE, varIgnore = NULL, varGeneralLab = "Variable", varSubgroupLab = "Variable group", varIncludeTotal = FALSE, varTotalInclude = FALSE, varTotalInSepRow = FALSE, rowVar = NULL, rowVarLab = NULL, rowVarDataLevels = NULL, rowOrder = "auto", rowOrderTotalFilterFct = NULL, rowOrderCatLast = NULL, rowVarInSepCol = NULL, rowVarFormat = NULL, rowVarTotalInclude = NULL, rowVarTotalByVar = NULL, rowVarTotalInSepRow = NULL, rowTotalLab = NULL, rowInclude0 = FALSE, rowAutoMerge = TRUE, emptyValue = "-", rowVarTotalPerc = NULL, colVar = NULL, colVarTotal = colVar, colVarTotalPerc = colVarTotal, colInclude0 = FALSE, colVarDataLevels = NULL, colTotalInclude = FALSE, colTotalLab = "Total", stats = NULL, statsExtra = NULL, statsVarBy = NULL, statsPerc = c("statN", "statm"), statsGeneralLab = "Statistic", statsValueLab = "StatisticValue", statsLabInclude = NULL, subjectVar = "USUBJID", filterFct = NULL, dataTotal = NULL, dataTotalPerc = dataTotal, dataTotalRow = NULL, dataTotalCol = NULL, type = "auto", byVar = NULL, byVarLab = NULL, checkVarDiffBySubj = "error", labelVars = NULL, outputType = "flextable", statsLayout = ifelse("DT" %in% outputType, "col", "row"), landscape = (style == "presentation"), margin = 1, rowPadBase = 14.4, title = NULL, footer = NULL, file = NULL, style = "report", colorTable = getColorPaletteTable(style = style), colHeaderTotalInclude = TRUE, colHeaderMerge = TRUE, fontsize = switch(style, report = 8, presentation = 10), fontname = switch(style, report = "Times", presentation = "Tahoma"), vline = "none", hline = "auto", pageDim = NULL, columnsWidth = NULL, expandVar = NULL, noEscapeVar = NULL, barVar = NULL, ... )
getSummaryStatisticsTable( data, var = NULL, varFlag = NULL, varLab = NULL, varLabInclude = length(var) > 1, varInclude0 = FALSE, varIgnore = NULL, varGeneralLab = "Variable", varSubgroupLab = "Variable group", varIncludeTotal = FALSE, varTotalInclude = FALSE, varTotalInSepRow = FALSE, rowVar = NULL, rowVarLab = NULL, rowVarDataLevels = NULL, rowOrder = "auto", rowOrderTotalFilterFct = NULL, rowOrderCatLast = NULL, rowVarInSepCol = NULL, rowVarFormat = NULL, rowVarTotalInclude = NULL, rowVarTotalByVar = NULL, rowVarTotalInSepRow = NULL, rowTotalLab = NULL, rowInclude0 = FALSE, rowAutoMerge = TRUE, emptyValue = "-", rowVarTotalPerc = NULL, colVar = NULL, colVarTotal = colVar, colVarTotalPerc = colVarTotal, colInclude0 = FALSE, colVarDataLevels = NULL, colTotalInclude = FALSE, colTotalLab = "Total", stats = NULL, statsExtra = NULL, statsVarBy = NULL, statsPerc = c("statN", "statm"), statsGeneralLab = "Statistic", statsValueLab = "StatisticValue", statsLabInclude = NULL, subjectVar = "USUBJID", filterFct = NULL, dataTotal = NULL, dataTotalPerc = dataTotal, dataTotalRow = NULL, dataTotalCol = NULL, type = "auto", byVar = NULL, byVarLab = NULL, checkVarDiffBySubj = "error", labelVars = NULL, outputType = "flextable", statsLayout = ifelse("DT" %in% outputType, "col", "row"), landscape = (style == "presentation"), margin = 1, rowPadBase = 14.4, title = NULL, footer = NULL, file = NULL, style = "report", colorTable = getColorPaletteTable(style = style), colHeaderTotalInclude = TRUE, colHeaderMerge = TRUE, fontsize = switch(style, report = 8, presentation = 10), fontname = switch(style, report = "Times", presentation = "Tahoma"), vline = "none", hline = "auto", pageDim = NULL, columnsWidth = NULL, expandVar = NULL, noEscapeVar = NULL, barVar = NULL, ... )
data |
Data.frame with dataset to consider for the summary table. |
var |
Character vector with variable(s) of |
varFlag |
Character vector, subset of |
varLab |
Named character vector with label for each variable
specified in |
varLabInclude |
Logical, if TRUE
the name of the summary statistic variable(s) ( |
varInclude0 |
Logical, should rows with no counts
for the count
|
varIgnore |
Vector with elements to ignore in the |
varGeneralLab |
String with general label for variable specified in |
varSubgroupLab |
String with general label for sub-group of categorical variable(s) for count table, 'Variable group' by default. This will be included in the final table header (see 'rowVarLab' attribute of the output). |
varIncludeTotal |
This argument is deprecated, please use: 'varTotalInclude' instead. |
varTotalInclude |
Should the total across all categories of
|
varTotalInSepRow |
Logical, should the total per variable be included in a separated row (by default) or in the row containing the header of the variable? |
rowVar |
Character vector with variable(s) to be included in the rows. If multiple variables are specified, the variables should be sorted in hierarchical order (e.g. body system class before adverse event term) and are nested in the table. |
rowVarLab |
Named character vector with
label for the |
rowVarDataLevels |
Data.frame with unique combinations of |
rowOrder |
Specify how the rows should be ordered in the final table, either a:
To specify different ordering methods for different |
rowOrderTotalFilterFct |
Function used to filter the data used to order the rows
based on total counts (in case |
rowOrderCatLast |
String with category to be printed in the last
row of each |
rowVarInSepCol |
Character vector with |
rowVarFormat |
(flextable output) Named list with special formatting for the |
rowVarTotalInclude |
Character vector with |
rowVarTotalByVar |
Character vector with a row variable
used to categorize the row total. |
rowVarTotalInSepRow |
Character vector with |
rowTotalLab |
(flextable output) string with label for the row with total. |
rowInclude0 |
Logical, if TRUE (FALSE by default),
include rows with no records, based on all combinations
of the |
rowAutoMerge |
(flextable output) Logical, if TRUE (by default) automatically merge rows, e.g. in case there is only one sub-category (e.g. categorical variable with only one group) or only one statistic per category. |
emptyValue |
String with placeholder used to fill the table for missing values, '-' by default. This value is typically used e.g. if not all statistics are computed for all specified row/col/var variables. |
rowVarTotalPerc |
Character vector with row variables by which the total
should be computed for the denominator for the percentage computation.
By default the total is only computed only by column (NULL by default).
If the total should be based on the total number of records per variable,
|
colVar |
Character vector with variable(s) to be included in columns.
If multiple variables are specified, the variables should
be sorted in hierarchical order,
and are included in multi-columns layout. |
colVarTotal |
String with column(s) considered to compute the total by,
reported in the header of the table, by default same as |
colVarTotalPerc |
String with column(s) considered to compute the total by,
used as denominator for the percentage computation, by default same as |
colInclude0 |
Logical, if TRUE (FALSE by default),
include columns with no records, based on all combinations
of the |
colVarDataLevels |
Data.frame with unique combinations of |
colTotalInclude |
Logical, if TRUE (FALSE by default) include the summary statistics across columns in a separated column. |
colTotalLab |
String, label for the total column 'Total' by default. |
stats |
(optional) Statistic(s) of interest to compute, either:
|
statsExtra |
(optional) Named list with functions for additional custom
statistics to be computed.
For example, to additionally compute the coefficient of variation, this can be set to:
|
statsVarBy |
String with variable in |
statsPerc |
String with 'base statistical variable' used to compute the percentage, either:
|
statsGeneralLab |
String with general label for statistics, 'Statistic' by default.
Only included if no |
statsValueLab |
String with label for the statistic value,
'StatisticValue' by default. |
statsLabInclude |
Logical, if TRUE include the statistic label
in the table. |
subjectVar |
String, variable of |
filterFct |
(optional) Function taking as input
the summary table with computed statistics and returning a subset
of the summary table.
|
dataTotal |
Data.frame used to extract the Total number of subject
per column in column header ('N = [X]').
It should contain the variables specified by |
dataTotalPerc |
Data.frame used to extract the total counts per column
for the computation of the percentage. |
dataTotalRow |
Data.frame used to extract the total count across all
elements of the row
variable, list of such data.frame for each |
dataTotalCol |
Data.frame from which the total across columns is
extracted (in case
If only a subset of the variables is specified in this list,
By default, |
type |
String with type of table:
|
byVar |
Variable(s) of |
byVarLab |
String with label for |
checkVarDiffBySubj |
String, 'error' (default), 'warning',
or 'none'.
Should an error, a warning, or nothing be produced
if a continuous variable ( |
labelVars |
(optional) Named character vector with label for
the row, column variable(s) or variable(s) to summarize. |
outputType |
String with output type:
|
statsLayout |
String with layout for the statistics names (in case more than one statistic is included), among:
|
landscape |
(flextable output) Logical, if TRUE the file is in landscape format. |
margin |
(flextable output) Margin in the document in inches
(1 by default).
This is used to specify the width of the table, from:
[ |
rowPadBase |
(flextable output) Base padding for row (in points), 14.4 by default (corresponds to 0.2 inches) |
title |
Character vector with title(s) for the table.
Set to NULL (by default) if no title should be included.
If multiple are specified, specified for each element of |
footer |
(flextable output) Character vector with footer(s) for the table. Set to NULL (by default) if no footer should be included. |
file |
(Optional) Name of the file the table should be exported to, either:
If NULL (by default), the summary table is not exported but only returned as output.
If |
style |
(flextable output) String with table style, either 'report' or 'presentation'. This parameter affects the fontsize, font family, color of the text and background, and table dimensions of the table. |
colorTable |
(flextable output) Named character vector with color for the table background/body/text/line,
e.g. created with the |
colHeaderTotalInclude |
Logical, if TRUE include the total of number of patients
( |
colHeaderMerge |
(flextable output) Logical, if TRUE (FALSE by default) the column header is merged. |
fontsize |
(flextable output) Integer with font size, by default:
8 if |
fontname |
(flextable output) String with font name, by default:
'Times' if |
vline |
(flextable output) String mentioning how vertical lines should be included in the body of the table, either:
|
hline |
(flextable output) String mentioning how horizontal lines should be included in the body of the table, either:
|
pageDim |
Numeric vector of length 2 with page width and height.
|
columnsWidth |
(expert mode) Column widths of the table. This is only used
for flextable and DT tables. |
expandVar |
(DT output) Character vector with variables of the summary table which should be expanded in the data. |
noEscapeVar |
(DT output) Character vector with variables of |
barVar |
(DT output) Character vector with variables of |
... |
(DT output) Extra parameters passed to the
|
Depending on the outputType
:
'data.frame-base': input summary table in a long format with all computed statistics
'data.frame': summary table in a wide format (
different columns for each colVar
), with specified labels
'flextable' (by default): flextable
object with summary table
'DT': datatable
object with summary table
If multiple outputType
are specified, a list of those objects, named
by outputType
.
If byVar
is specified, each object consists of a list of tables,
one for each element in byVar
.
Laure Cougnaud
Tables of summary statistics or count tables are created. These tables can be exported as in-text table to a Clinical Study Report (Word format), a topline presentation (PowerPoint format), or as interactive table to an html document.
To get started with the package, see:vignette("inTextSummaryTable-introduction", package = "inTextSummaryTable")
To get example code for standard in-text tables created with the package,
see:vignette("inTextSummaryTable-standardTables", package = "inTextSummaryTable")
The main function: getSummaryStatisticsTable
enables
to create ready in-text table.
Maintainer: Laure Cougnaud [email protected]
Authors:
Michela Pasetto [email protected]
Other contributors:
Margaux Faes (tests) [reviewer]
Open Analytics [copyright holder]
Useful links:
Report bugs at https://github.com/openanalytics/inTextSummaryTable/issues
Arguments used across the functions of the inTextSummaryTable package.
data |
Data.frame with dataset to consider for the summary table. |
summaryTable |
A |
var |
Character vector with variable(s) of |
varFlag |
Character vector, subset of |
varLabInclude |
Logical, if TRUE
the name of the summary statistic variable(s) ( |
rowVar |
Character vector with variable(s) to be included in the rows. If multiple variables are specified, the variables should be sorted in hierarchical order (e.g. body system class before adverse event term) and are nested in the table. |
rowVarInSepCol |
Character vector with |
rowVarLab |
Named character vector with
label for the |
statsVar |
Character vector with columns of |
rowVarTotalInclude |
Character vector with |
rowVarTotalInSepRow |
Character vector with |
colVar |
Character vector with variable(s) to be included in columns.
If multiple variables are specified, the variables should
be sorted in hierarchical order,
and are included in multi-columns layout. |
colTotalInclude |
Logical, if TRUE (FALSE by default) include the summary statistics across columns in a separated column. |
colTotalLab |
String, label for the total column 'Total' by default. |
subjectVar |
String, variable of |
statsLayout |
String with layout for the statistics names (in case more than one statistic is included), among:
|
statsValueLab |
String with label for the statistic value,
'StatisticValue' by default. |
statsExtra |
(optional) Named list with functions for additional custom
statistics to be computed.
For example, to additionally compute the coefficient of variation, this can be set to:
|
type |
String with type of table:
|
statsLabInclude |
Logical, if TRUE include the statistic label
in the table. |
title |
Character vector with title(s) for the table.
Set to NULL (by default) if no title should be included.
If multiple are specified, specified for each element of |
pageDim |
Numeric vector of length 2 with page width and height.
|
columnsWidth |
(expert mode) Column widths of the table. This is only used
for flextable and DT tables. |
labelVars |
(optional) Named character vector with label for
the row, column variable(s) or variable(s) to summarize. |
No return value, used for the documentation of R functions
Common arguments for the functionalities of the inTextSummaryTable package for DT export.
expandVar |
(DT output) Character vector with variables of the summary table which should be expanded in the data. |
pageDim |
(DT output) Numeric vector of length 2 with page width and height,
in number of rows (currently only
the height is used (e.g. |
noEscapeVar |
(DT output) Character vector with variables of |
barVar |
(DT output) Character vector with variables of |
file |
String with path of the file where the table should be exported.
The file should have the extension: '.docx'.
If NULL, the summary table is not exported but only returned as output.
If |
No return value, used for the documentation of R functions for 'DT' output
Common arguments for the functionalities of the inTextSummaryTable package for flextable export.
style |
(flextable output) String with table style, either 'report' or 'presentation'. This parameter affects the fontsize, font family, color of the text and background, and table dimensions of the table. |
rowTotalLab |
(flextable output) string with label for the row with total. |
rowAutoMerge |
(flextable output) Logical, if TRUE (by default) automatically merge rows, e.g. in case there is only one sub-category (e.g. categorical variable with only one group) or only one statistic per category. |
rowVarFormat |
(flextable output) Named list with special formatting for the |
rowPadBase |
(flextable output) Base padding for row (in points), 14.4 by default (corresponds to 0.2 inches) |
fontname |
(flextable output) String with font name, by default:
'Times' if |
fontsize |
(flextable output) Integer with font size, by default:
8 if |
margin |
(flextable output) Margin in the document in inches
(1 by default).
This is used to specify the width of the table, from:
[ |
colorTable |
(flextable output) Named character vector with color for the table background/body/text/line,
e.g. created with the |
landscape |
(flextable output) Logical, if TRUE the file is in landscape format. |
footer |
(flextable output) Character vector with footer(s) for the table. Set to NULL (by default) if no footer should be included. |
vline |
(flextable output) String mentioning how vertical lines should be included in the body of the table, either:
|
hline |
(flextable output) String mentioning how horizontal lines should be included in the body of the table, either:
|
file |
String with path of the file where the table should be exported.
The file should have the extension: '.html'.
If NULL, the summary table is not exported but only returned as output.
If |
colHeaderMerge |
(flextable output) Logical, if TRUE (FALSE by default) the column header is merged. |
No return value, used for the documentation of R functions for 'flextable' output
In the in-text package, different set of statistics are available.
The statistics are first computed as numeric ('Base statistics' section below), then formatted to be displayed in the table ('Formatted statistics' section below).
No return value, used for the documentation of
the stats
parameter
In the in-text package, the following 'base statistics' are reported in the summary table:
for a continuous variable:
'statMean': variable mean
'statSD': variable standard deviation
'statSE': variable standard error
'statMedian': variable median
'statMin': variable minimum
'statMax': variable maximum
During the computation of the statistics, if multiple and different values are available for a specific variable and subject ID (by row/column): an error is triggered.
for a categorical and continuous variable (or the full table):
'statN': number of subjects
'statm': number of records
'statPercN' (or 'statPercm'): percentage of subjects (or records) for the specific group
'statPercTotalN' (or 'statPercTotalm'): number of subjects (or records) considered for the total (denominator) of the percentage
The percentage and denominator of the percentage are based
on the number of subjects or records depending on
the statsPerc
parameter.
These statistics are reported as numeric and non rounded in the summary table, and are typically used as input for the formatted statistics, or for plots.
In the in-text package, the following formatted statistics can be reported in the final output table.
for a continuous variable:
base statistics:
'Mean': formatted mean
'Median': formatted median
'SE': formatted standard error
'SD': formatted standard deviation
'Min': formatted minimum
'Max': formatted maximum
multiple:
'summary-default': default set of statistics for a continuous variable: 'n', 'Mean', 'SD', 'SE', 'Median', 'Min', 'Max'
'summary': all statistics available for a continuous variable: 'n', 'Mean', 'SD', 'SE', 'Median', 'Min', 'Max', '%', 'm'
combined statistics:
'median (range)': median (minimum,maximum)
'median\n(range)': median and (minimum, maximum) below (linebreak)
'mean (sd)': mean and standard deviation
'mean (se)': mean and standard error
'mean (range)': mean and (minimum, maximum)
'(min, max)': (minimum, maximum)
for a categorical or continuous variable (or the full table):
base statistics:
'n': formatted number of subjects
'm': formatted number of records
'%': formatted percentage of subjects
'%m': formatted percentage of records.
Note: this is only available if the percentage of records is reported
(statsPerc
set to 'statm').
multiple:
'count-default': default set of statistics for a categorical variable: 'n', '%'
'count': all statistics available for a categorical variable: 'n', '%', 'm'
combined statistics:
'n (%)': number of subjects (and associated percentage)
'n/N (%)': number of subjects/total number of subjects (percentage)
'm (%)': number of records (and associated percentage).
Note: this is only available if the percentage of records is reported
(statsPerc
set to 'statm').
#' These statistics are specified via the stats
parameter
(or type
parameter of getStats
).
These statistics are reported as text variables
in the summary table (as data.frame),
and typically displayed inside the final table.
In general, all rounding is handled with roundHalfUpTextFormat
.
statistics for continuous variable:
if the number of decimals (nDecCont
) is specified:
statistics are rounded with the following number of decimals,
based on:
'Min', 'Max': nDecCont
'Mean', 'SD', 'Median': nDecCont
+ 1
'SE': nDecCont
+ 2
Note that the number of decimals is extracted
from standard rules/data is the variable of interest
is specified (e.g. via var
in getStatsData
).
if the number of decimals is not specified:
a default format is set via the formatC
function.
statistics for counts:
number of subjects, records are rounded with the number of decimals
specified via nDecN
or nDecm
(0 by default)
percentages are formatted by default with formatPercentage
.
'n (%)' and 'm (%)':
if the percentage of subjects/records is missing, '-' is reported
if the number of subjects/records is 0, '0' is reported instead of '0 (0%)'
otherwise the number and percentage of subjects/records are formatted as specified
'n/N (%)':
if the percentage of subjects is missing, '-' is reported
if the number of subjects is 0, '0' is reported instead of '0/... (0%)'
otherwise the number and percentage of subjects and total are formatted as specified
Common arguments for the for the statistics utility functions of the inTextSummaryTable package.
x |
Numeric vector. |
na.rm |
Logical, should NA value(s) be removed (FALSE by default)? |
No return value, used for the documentation of stat utility R functions
Page dimension for powerpoints
pageDimPresentation
pageDimPresentation
An object of class numeric
of length 2.
This function is for internal use within
the computeSummaryStatisticsTable
function.
postProcessVarFlag(summaryTable, varFlag)
postProcessVarFlag(summaryTable, varFlag)
summaryTable |
Summary table as created internally in
|
varFlag |
Character vector, subset of |
This includes:
converting the records from a flag variable
for the 'variableGroup' variable
from 'Y' to NA_character_
filter records from a flag variable with variableGroup set as 'N'
Summary table with
Laure Cougnaud
The standard error of the mean is computed as:
, with:
: standard deviation of
x
se(x, na.rm = FALSE)
se(x, na.rm = FALSE)
x |
Numeric vector. |
na.rm |
Logical, should NA value(s) be removed (FALSE by default)? |
Numeric vector with standard error of the mean
Laure Cougnaud
Other stats utility functions:
cv()
,
geomCV()
,
geomMean()
,
geomSD()
,
geomSE()
se(rnorm(1000))
se(rnorm(1000))
The user can either specify a variable for the standard error
(seVar
),
or directly the variables for the minimum and maximum values for the error
bars (minVar
, maxVar
).
subjectProfileSummaryPlot( data, xVar = NULL, xLab = getLabelVar(xVar, labelVars = labelVars), xAxisExpand = waiver(), xGap = NULL, xGapDiffNew = NULL, meanVar = "statMean", seVar = if ("statSE" %in% colnames(data)) "statSE", minVar = NULL, maxVar = NULL, yLab = paste(c(sub("^stat", "", meanVar), if (!is.null(minVar) & !is.null(maxVar)) { paste0("(", sub("^stat", "", minVar), ", ", sub("^stat", "", maxVar), ")") } else if (!is.null(seVar)) paste("+-", sub("^stat", "", seVar))), collapse = " "), facetVar = NULL, facetScale = "free_y", colorVar = NULL, colorLab = getLabelVar(colorVar, labelVars = labelVars), colorPalette = NULL, labelVars = NULL, useLinetype = TRUE, linetypePalette = NULL, useShape = TRUE, shapePalette = NULL, jitter = NULL, title = NULL, caption = NULL, yTrans = NULL, yLim = NULL, xLim = NULL, yAxisExpand = c(0.05, 0.05), yLimExpand = NULL, xAxisLabs = NULL, sizePoint = GeomPoint$default_aes$size, sizeLine = GeomLine$default_aes$size, sizeLabel = GeomText$default_aes$size, widthErrorBar = GeomErrorbar$default_aes$width, tableText = NULL, tableTextFontface = 1, tableHeight = 0.1, tableYAxisLabs = !is.null(colorVar), tablePlotMargin = unit(0, "pt"), label = FALSE, labelPadding = unit(1, "lines"), byVar = NULL, hLine = NULL, hLineColor = "black", hLineLty = "solid", vLine = NULL, vLineColor = "black", vLineLty = "solid", style = "report", fontname = switch(style, report = "Times", presentation = "Tahoma"), fontsize = switch(style, report = 8, presentation = 10), themeFct = switch(style, report = theme_classic, presentation = theme_bw), themeIncludeVerticalGrid = TRUE, ggExtra = NULL, legendPosition = ifelse(!is.null(tableText), "none", "bottom"), ... )
subjectProfileSummaryPlot( data, xVar = NULL, xLab = getLabelVar(xVar, labelVars = labelVars), xAxisExpand = waiver(), xGap = NULL, xGapDiffNew = NULL, meanVar = "statMean", seVar = if ("statSE" %in% colnames(data)) "statSE", minVar = NULL, maxVar = NULL, yLab = paste(c(sub("^stat", "", meanVar), if (!is.null(minVar) & !is.null(maxVar)) { paste0("(", sub("^stat", "", minVar), ", ", sub("^stat", "", maxVar), ")") } else if (!is.null(seVar)) paste("+-", sub("^stat", "", seVar))), collapse = " "), facetVar = NULL, facetScale = "free_y", colorVar = NULL, colorLab = getLabelVar(colorVar, labelVars = labelVars), colorPalette = NULL, labelVars = NULL, useLinetype = TRUE, linetypePalette = NULL, useShape = TRUE, shapePalette = NULL, jitter = NULL, title = NULL, caption = NULL, yTrans = NULL, yLim = NULL, xLim = NULL, yAxisExpand = c(0.05, 0.05), yLimExpand = NULL, xAxisLabs = NULL, sizePoint = GeomPoint$default_aes$size, sizeLine = GeomLine$default_aes$size, sizeLabel = GeomText$default_aes$size, widthErrorBar = GeomErrorbar$default_aes$width, tableText = NULL, tableTextFontface = 1, tableHeight = 0.1, tableYAxisLabs = !is.null(colorVar), tablePlotMargin = unit(0, "pt"), label = FALSE, labelPadding = unit(1, "lines"), byVar = NULL, hLine = NULL, hLineColor = "black", hLineLty = "solid", vLine = NULL, vLineColor = "black", vLineLty = "solid", style = "report", fontname = switch(style, report = "Times", presentation = "Tahoma"), fontsize = switch(style, report = 8, presentation = 10), themeFct = switch(style, report = theme_classic, presentation = theme_bw), themeIncludeVerticalGrid = TRUE, ggExtra = NULL, legendPosition = ifelse(!is.null(tableText), "none", "bottom"), ... )
data |
Data.frame with summary statistics to represent in the plot,
e.g. a |
xVar |
String, variable of |
xLab |
String with label for the |
xAxisExpand |
Object passed to the 'expand' parameter of:
|
xGap |
(optional) Numeric vector of length 2 for which
a gap should be created in the x-axis.
Only available if |
xGapDiffNew |
Numeric vector of length 2 with new range
of the |
meanVar |
String, variable of |
seVar |
String, variable of |
minVar , maxVar
|
String, variables of |
yLab |
String with label for the y-axis.
If different labels should be used for different elements of
|
facetVar |
Character vector, variable(s) of |
facetScale |
String with type of scale used for facetting, 'free_y' by default (fixed scale in the x-axis and free in the y-axis). |
colorVar |
String, variable of |
colorLab |
String, label for |
colorPalette |
(named) Vector with color palette. |
labelVars |
Named string with variable labels (names are the variable code). |
useLinetype |
Logical, if TRUE (FALSE by default) use also linetype
to differenciate the variable specified via |
linetypePalette |
Vector with linetype(s), in case |
useShape |
Logical, if TRUE (by default) |
shapePalette |
Named vector with shape palette for |
jitter |
Numeric with jitter for the x-axis, only used if |
title |
String with title for the plot.
If different labels should be used for different elements of
|
caption |
String with caption for the plot, NULL by default. |
yTrans |
(optional) String with transformation for the y-axis.
Currently only 'log10' (or NULL, default) is available.
In case error bars go in the negative, their values are set to a 'small enough' value for plotting:
|
yLim |
Vector of the length 2 with limits for the y-axis. |
xLim |
Vector of the length 2 with limits for the x-axis. |
yAxisExpand |
Expansion constants for the limits for the y-axis.
See the documentation of the |
yLimExpand |
This parameter is deprecated, use |
xAxisLabs |
(optional) Named character vector with labels for the x-axis. |
sizePoint |
Size for the point. |
sizeLine |
Size for the line linking means and error bars. |
sizeLabel |
Size for the label, only used if |
widthErrorBar |
Numeric vector of length 1 with width of error bar. |
tableText |
(optional) Character vector with colname of |
tableTextFontface |
Font face for the text included in the table. |
tableHeight |
Numeric of length 1 with height for the table. |
tableYAxisLabs |
Logical, if TRUE (by default)
the labels of the |
tablePlotMargin |
Margin between the plot and the table,
expressed as |
label |
Logical or expression or list of expression.
Points are labelled with |
labelPadding |
Amount of padding (space) between each point
and its |
byVar |
Variable(s) of |
hLine |
(optional) numeric with y-intercept of line(s) to be added.
If different thresholds should be used for different elements of the
|
hLineColor |
String with color for |
hLineLty |
String with linetype for |
vLine |
(optional) numeric with x-intercept of line(s) to be added.
If different thresholds should be used for different elements of the
|
vLineColor |
String with color for |
vLineLty |
String with linetype for |
style |
String with subject profile style.
This affects the parameters: |
fontname |
String with font name,
by default 'Times' if |
fontsize |
Numeric vector of length 1 with font size,
by default 8 if |
themeFct |
Function with ggplot2 theme,
by default |
themeIncludeVerticalGrid |
Logical, if TRUE (by default)
include theme vertical grid lines (if present in |
ggExtra |
Extra |
legendPosition |
String with legend position.
By default, 'bottom' of |
... |
Additional parameters for |
ggplot
object or list of such
objects of byVar
is specified.
Laure Cougnaud
ggplot
of a text variable of interest.The labels extracted based on the text
parameter
and displayed at the x-position based on xVar
and the y-position based on
colorVar
.
Each group specified in the color variables are displayed in different
lines in the plot.
subjectProfileSummaryTable( data, xVar, text, xLim = NULL, colorVar = NULL, colorPalette = NULL, colorLab = getLabelVar(colorVar, labelVars = labelVars), fontface = 1, xLab = NULL, labelVars = NULL, caption = NULL, showLegend = TRUE, legendPosition = ifelse(showLegend, "right", "none"), yAxisLabs = FALSE, xAxisLabs = NULL, style = "report", fontname = switch(style, report = "Times", presentation = "Tahoma"), fontsize = switch(style, report = 8, presentation = 10), pointSize = 1.5, themeFct = switch(style, report = theme_classic, presentation = theme_bw), textSize = fontsize/ggplot2::.pt, xTrans = NULL )
subjectProfileSummaryTable( data, xVar, text, xLim = NULL, colorVar = NULL, colorPalette = NULL, colorLab = getLabelVar(colorVar, labelVars = labelVars), fontface = 1, xLab = NULL, labelVars = NULL, caption = NULL, showLegend = TRUE, legendPosition = ifelse(showLegend, "right", "none"), yAxisLabs = FALSE, xAxisLabs = NULL, style = "report", fontname = switch(style, report = "Times", presentation = "Tahoma"), fontsize = switch(style, report = 8, presentation = 10), pointSize = 1.5, themeFct = switch(style, report = theme_classic, presentation = theme_bw), textSize = fontsize/ggplot2::.pt, xTrans = NULL )
data |
Data.frame (in long format) with data for the table. |
xVar |
String, variable of |
text |
Character vector with colnames of |
xLim |
Vector of the length 2 with limits for the x-axis. |
colorVar |
String, variable of |
colorPalette |
(named) Vector with color palette. |
colorLab |
String, label for |
fontface |
Numeric, fontface for the text. |
xLab |
String with label for the x-axis. |
labelVars |
Named string with variable labels (names are the variable code). |
caption |
String with caption for the plot, NULL by default. |
showLegend |
Logical, should the legend be displayed? TRUE by default. |
legendPosition |
String with legendPosition, 'right' by default. |
yAxisLabs |
Logical, if TRUE include the labels in the y-axis. |
xAxisLabs |
Vector with labels for the x-axis if |
style |
String with subject profile style.
This affects the parameters: |
fontname |
String with font name,
by default 'Times' if |
fontsize |
Numeric vector of length 1 with font size,
by default 8 if |
pointSize |
Numeric indicating the size of points in the legend, 1.5 by default |
themeFct |
Function with ggplot2 theme,
by default |
textSize |
Size for the text. |
xTrans |
(optional) ggplot2 transformation for the x-axis. |
ggplot
object
Laure Cougnaud and Michela Pasetto
summaryTable
The summary statistics are computed in
computeSummaryStatisticsTable
,
which creates a summaryTable
object.
This object is exported to diverse formats via
export
Multiple summaryTable
objects are combined
together with combine.summaryTable
.
The summaryTable
is an intermediary
object of the package.
This contains the summary statistics as data.frame.
This object contains:
the row and column variable(s)
the computed statistic(s):
If type
is:
'summaryTable':
'statN': number of subjects
'statMean': mean of var
'statSD': standard deviation of var
'statSE': standard error of var
'statMedian': median of var
'statMin': minimum of var
'statMax': maximum of var
'statPerc': percentage of subjects
'statPercTotalN': total number of subjects based on dataTotalPerc
,
denominator of statPerc
'statm': number of records
'countTable':
'statN': number of subjects
'statPercN' (or 'statPercm'): percentage of subjects
(or records depending on statsPerc
)
'statPercTotalN' (or 'statPercTotalm'): total number of
subjects (or records) based on dataTotalPerc
, and used as
denominator of statPercN
(or 'statPercm')
'statm': number of records
computed statistics.
The statistics are stored in columns corresponding
to names of the statsVar
.
If the specified statistics are not named and of length
1, the statistics are stored in a column called: 'Statistic'.
variables:
'variable': variable name in case var
is of length > 1
'variableGroup': in case var
is of length > 1 and for
variable(s) used for count: elements of the variable
'isTotal': variable with logical flag, TRUE if the record contain the total by column
Additionally, the output contains an extra attribute 'summaryTable', which is a list composed of:
'statsVar': column name(s) of summary table with computed statistics included in the final table
'rowVar': column name(s) of summary table with row variable included in the final table. This parameter should be mainly used for qualitative variables and 'nests' together different rows in the final output table.
'rowVarLab': labels corresponding to the 'rowVar' attribute
'rowVarTotalInclude': row variables whose total will be included:
rowVarTotalInclude
and 'variableGroup' if the variable total should be included
'rowVarTotalInSepRow': row variables whose total will be included in a separated row:
rowVarTotalInSepRow
and 'variableGroup' if varTotalInSepRow
'colVar': column name(s) of summary table with column variable included in the final table
'colTotalLab': label for the total
Not relevant
Default colors are
header: white text on a blue background
body: black text on a grey background
footer: black text on a white background.
tableColorsPresentation
tableColorsPresentation
An object of class character
of length 11.
Default colors are black text on a white background.
tableColorsReport
tableColorsReport
An object of class character
of length 7.
The following framework is followed:
get the unique elements in the vectors
for each of this element: get the average order across the different vectors
put variable
, if present as second to last element
put variableGroup
, if present, as last element
order the unique elements based on the extracted order
uniqueVarWithOrder(...)
uniqueVarWithOrder(...)
... |
Lists |
Vector with unique and ordered elements.
Laure Cougnaud
This function is mainly a wrapper on write.table
,
with the specific options:
no rownames
no quoting
tab separator
writeTable(x, file, ...)
writeTable(x, file, ...)
x |
Data.frame to export to the table, or list of such tables. |
file |
String with text file to export to. |
... |
Any parameters passed to the |
No returned value, the object x
is exported to the specified file
.
Laure Cougnaud