Type: | Package |
Title: | Creation of in-Text Summary Table |
Version: | 3.3.3 |
Date: | 2024-06-12 |
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. |
Imports: | clinUtils (≥ 0.1.0), cowplot, flextable (≥ 0.5.5), ggplot2, ggrepel, magrittr, methods, officer, plyr, reshape2 (≥ 1.4), scales, stats, utils |
Suggests: | htmltools, knitr, rmarkdown, pander, testthat, xml2, tools, dplyr, tibble, extrafont |
URL: | https://github.com/openanalytics/inTextSummaryTable |
BugReports: | https://github.com/openanalytics/inTextSummaryTable/issues |
License: | MIT + file LICENSE |
RoxygenNote: | 7.3.1 |
VignetteBuilder: | knitr |
SystemRequirements: | pandoc (to export an interactive summary table to a file) |
NeedsCompilation: | no |
Packaged: | 2024-06-12 17:36:37 UTC; root |
Author: | Laure Cougnaud [aut, cre], Michela Pasetto [aut], Margaux Faes [rev] (tests), Open Analytics [cph] |
Maintainer: | Laure Cougnaud <laure.cougnaud@openanalytics.eu> |
Repository: | CRAN |
Date/Publication: | 2024-06-12 18:30:02 UTC |
inTextSummaryTable: creation of in-text summary table
Description
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.
Details
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.
Author(s)
Maintainer: Laure Cougnaud laure.cougnaud@openanalytics.eu
Authors:
Michela Pasetto michela.pasetto@openanalytics.eu
Other contributors:
Margaux Faes (tests) [reviewer]
Open Analytics [copyright holder]
See Also
Useful links:
Report bugs at https://github.com/openanalytics/inTextSummaryTable/issues
Check if variable(s) are present in reference: either in columns in a dataset or in reference set.
Description
Filter variables not present in the data or in reference set with a warning, and only returned filtered vector, or NULL if empty.
Usage
checkVar(
var,
varLabel,
varUncheck = NULL,
varRef,
refLabel = ifelse(!missing(varRef), "reference variable", "data"),
data,
msgType = c("warning", "error")
)
Arguments
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. |
Value
Depending on msgType
:
warning
: warning is printed in the console, and avar
filtered with element not indata
or inrefSet
is returned. If filteredvar
is empty, NULL is returned.error
: an error is triggered.
Author(s)
Laure Cougnaud
Check the varLabInclude
variable.
Description
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
Usage
checkVarLabInclude(var, varLabInclude = length(var) > 1)
Arguments
var |
String with variable to check. |
varLabInclude |
Logical, if TRUE
the name of the summary statistic variable(s) ( |
Value
(Updated) varLabInclude
Author(s)
Laure Cougnaud
Combine objects
Description
Combine objects
Usage
combine(...)
Arguments
... |
Extra parameters for the corresponding method. |
See Also
combine.summaryTable
to combine summaryTable
objects.
Combine summary statistics table
Description
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).
Usage
## S3 method for class 'summaryTable'
combine(..., summaryTables, combineVar = NULL, combineDir = c("row", "col"))
Arguments
... |
|
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
( |
Details
In case only a set of tables contain categorical variable, in nested rows, so the
variable
andvariableGroup
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.
Value
A combined summaryTable
.
Author(s)
Laure Cougnaud
Combine the column total for a combined summary table
Description
Combine the column total for a combined summary table
Usage
combineColTotal(summaryTable, attrs)
Arguments
summaryTable |
Combined summary table |
attrs |
Nested list with attributes of each summary table. |
Value
summary table, with combined total columns
Author(s)
Laure Cougnaud
Create a data.frame combining a set of records from same or multiple variables.
Description
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.
Usage
combineVariables(
data,
paramsList,
newVar,
labelVars = NULL,
fctTest = "==",
includeAll = FALSE,
labelAll = "Any"
)
Arguments
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 |
Value
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
.
Author(s)
Laure Cougnaud
Compute summary statistics of interest of an unique variable of interest.
Description
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 continuousvar
an indicative message is triggered if multiple but identical records are available for
subjectVar
and a continuousvar
Usage
computeSummaryStatistics(
data,
var = NULL,
varTotalInclude = FALSE,
statsExtra = NULL,
subjectVar = "USUBJID",
filterEmptyVar = TRUE,
type = "auto",
checkVarDiffBySubj = c("error", "warning", "none"),
msgLabel = NULL,
msgVars = NULL
)
Arguments
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 |
Value
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
Author(s)
Laure Cougnaud
Compute summary statistics by specified rowVar
and colVar
Description
Compute summary statistics by specified rowVar
and colVar
Usage
computeSummaryStatisticsByRowColVar(
data,
var = NULL,
varLab = getLabelVar(var = var, data = data, labelVars = labelVars),
varInclude0 = FALSE,
varLabInclude = length(var) > 1,
varTotalInclude = FALSE,
type = "auto",
rowVar = NULL,
rowInclude0 = FALSE,
rowVarDataLevels = NULL,
colVar = NULL,
colInclude0 = FALSE,
colVarDataLevels = NULL,
subjectVar = "USUBJID",
labelVars = NULL,
statsExtra = NULL,
msgLabel = NULL,
checkVarDiffBySubj = "error"
)
Arguments
data |
Data.frame with dataset to consider for the summary table. |
var |
Character vector with variable(s) of |
varLab |
Named character vector with label for each variable
specified in |
varInclude0 |
Logical, should rows with no counts
for the count
|
varLabInclude |
Logical, if TRUE
the name of the summary statistic variable(s) ( |
varTotalInclude |
Should the total across all categories of
|
type |
String with type of 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. |
rowInclude0 |
Logical, if TRUE (FALSE by default),
include rows with no records, based on all combinations
of the |
rowVarDataLevels |
Data.frame with unique combinations of |
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. |
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 |
subjectVar |
String, variable of |
labelVars |
(optional) Named character vector with label for
the row, column variable(s) or variable(s) to summarize. |
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:
|
checkVarDiffBySubj |
String, 'error' (default), 'warning',
or 'none'.
Should an error, a warning, or nothing be produced
if a continuous variable ( |
Value
data.frame of class 'countTable' or 'summaryTable',
depending on the 'type' parameter; with statistics in columns,
either if type
is:
'summaryTable':
'N': number of subjects
'Mean': mean of
var
'SD': standard deviation of
var
'SE': standard error of
var
'Median': median of
var
'Min': minimum of
var
'Max': maximum of
var
'm': number of records
'countTable':
'N': number of subjects
'm': number of records
Author(s)
Laure Cougnaud
Compute summary statistics for a specific dataset and variables of interest
Description
Compute summary statistics for a specific dataset and variables of interest
Usage
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"
)
Arguments
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 ( |
Value
An object summaryTable
or list of such objects if
byVar
is specified.
Author(s)
Laure Cougnaud
Compute summary statistics total table.
Description
Compute summary statistics total table.
Usage
computeSummaryStatisticsTableTotal(
data,
colVar = NULL,
colVarTotal = colVar,
rowVarTotal = NULL,
var = NULL,
varLab = getLabelVar(var, data = data, labelVars = labelVars),
colTotalLab = "Total",
colInclude0 = FALSE,
colTotalInclude = FALSE,
dataTotalCol = NULL,
colVarDataLevels = NULL,
colVarLevels = NULL,
subjectVar = "USUBJID",
labelVars = NULL,
msgLabel = "total",
checkVarDiffBySubj = "error"
)
Arguments
data |
Data.frame with dataset to consider for the summary 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. |
colVarTotal |
Character vector with column(s) considered to compute the total. This could also contain 'variable'. |
rowVarTotal |
Character vector with row(s) considered to compute the total. This could also contain 'variable'. |
var |
Character vector with variable(s) of |
colTotalLab |
String, label for the total column 'Total' by default. |
colTotalInclude |
Logical, if TRUE (FALSE by default) include the summary statistics across columns in a separated column. |
dataTotalCol |
Data.frame from which the total across columns is
extracted (in case |
colVarLevels |
list with levels of each |
subjectVar |
String, variable of |
labelVars |
(optional) Named character vector with label for
the row, column variable(s) or variable(s) to summarize. |
msgLabel |
(optional) String with label for the data ('total' by default), included in the message/warning for checks. |
Value
data.frame with total table.
Author(s)
Laure Cougnaud
Convert summary statistics table to flextable
Description
Convert summary statistics table to flextable
Usage
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
)
Arguments
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. |
Value
flextable
object with summary table
If summaryTable
is a list of summary tables,
returns a list of flextable
.
Author(s)
Laure Cougnaud
Convert flag variable to a format such as only the flagged records are counted in the summary table.
Description
Convert flag variable to a format such as only the flagged records are counted in the summary table.
Usage
convertVarFlag(x)
Arguments
x |
Character or factor variable with flag variable, should contain elements: 'Y' and 'N', or ” (for missing value). |
Value
Formatted factor variable with levels: 'Y' & 'N'. Empty strings have been converted to NA.
Author(s)
Laure Cougnaud
Convert rowVar
, colVar
and character var
in data
to factor
Description
Convert rowVar
, colVar
and character var
in data
to factor
Usage
convertVarRowVarColVarToFactor(data, rowVar = NULL, colVar = NULL, var = NULL)
Arguments
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 |
Value
Updated data
Author(s)
Laure Cougnaud
Convert a variable to a factor with levels in specified order.
Description
Convert a variable to a factor with levels in specified order.
Usage
convertVarToFactorWithOrder(
data,
var,
otherVars = NULL,
colVar = NULL,
colTotalLab = "Total",
method = c("auto", "alphabetical", "total"),
totalFilterFct = NULL,
totalVar = "statN",
catLast = NULL
)
Arguments
data |
Data.frame with dataset to consider for the summary table. |
var |
String with variable of |
otherVars |
Character vector with other variable(s) of |
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. |
method |
Ordering method to use, either:
|
totalFilterFct |
(optional) Function which returns a subset of the data of interest, to filter the total data considered for the ordering. |
totalVar |
String with variable of |
catLast |
String with last category (if any). Set to NULL if no specific category should be included as last element. |
Value
Factor var
variable of data
with specified order.
Author(s)
Laure Cougnaud
Convert vector to a bincode of 0/1 based on consecutive values in the vector.
Description
Convert vector to a bincode of 0/1 based on consecutive values in the vector.
Usage
convertVectToBinary(x)
Arguments
x |
Vector. |
Value
Integer vector of same length than x
.
Author(s)
Laure Cougnaud
Examples
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.
Description
Create a flextable, setting the column names to syntactic names if it is not the case.
Usage
createFlextableWithHeader(
data,
headerDf = NULL,
title = NULL,
includeRownames = TRUE,
colHeaderMerge = TRUE
)
Arguments
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. |
Value
list with:
'ft':
flextable
'colsData': Named vector with original column names, with names set to new syntactic names.
Author(s)
Laure Cougnaud
Compute the percentage coefficient of variation, (in a scale from 0 to 100).
Description
The coefficient of variation is computed as:
\frac{\sigma(x)}{\bar{x}}*100
, with:
\sigma(x)
: standard deviation ofx
\bar{x}
: arithmetic mean ofx
Usage
cv(x, na.rm = FALSE)
Arguments
x |
Numeric vector. |
na.rm |
Logical, should NA value(s) be removed (FALSE by default)? |
Value
Numeric vector of length 1 with coefficient of variation.
Author(s)
Laure Cougnaud
See Also
Other stats utility functions:
geomCV()
,
geomMean()
,
geomSD()
,
geomSE()
,
se()
Examples
# coefficient of variation of normal distribution tends to 100%
cv(rnorm(n = 1000, mean = 1, sd = 1))
Export an object
Description
Export an object
Usage
export(...)
Arguments
... |
Extra parameters for the corresponding method. |
See Also
export.summaryTable
to export summaryTable
objects.
Export a summary table to docx
, pptx
or html
format (interactive table)
Description
The use of export
is recommended.
exportSummaryStatisticsTable
is retained for
back-compatibility.
Usage
## 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,
...
)
Arguments
... |
(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 |
Value
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
.
Functions
-
export(summaryTable)
: exportsummaryTable
object
Author(s)
Laure Cougnaud
Export flextable to docx file
Description
Export flextable to docx file
Usage
exportFlextableToDocx(
object,
file,
landscape = FALSE,
breaksAfter = if (!inherits(object, "flextable")) seq_along(object) else 1
)
Arguments
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 |
Value
no returned value, the object
is exported to a docx file.
Author(s)
Laure Cougnaud
Export summary table to an interactive DT table, e.g. to be exported into an html document.
Description
Export summary table to an interactive DT table, e.g. to be exported into an html document.
Usage
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,
...
)
Arguments
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
|
Value
A datatable
object.
Author(s)
Laure Cougnaud
Export summary table to a flextable object, e.g. to be exported in Word or PowerPoint.
Description
Export summary table to a flextable object, e.g. to be exported in Word or PowerPoint.
Usage
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
)
Arguments
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. |
Value
flextable
object with summary table
If summaryTable
is a list of summary tables,
returns a list of flextable
.
Author(s)
Laure Cougnaud
Format superscript/subscripts/bold cells in a flextable.
Superscript should be indicated as: 'a^{b}
',
subscript as 'a_{b}
' and bold as 'bold{a}
' in the
the input summary table.
Description
Format superscript/subscripts/bold cells in a flextable.
Superscript should be indicated as: 'a^{b}
',
subscript as 'a_{b}
' and bold as 'bold{a}
' in the
the input summary table.
Usage
formatCustomFlextable(
dataTable,
ft,
fontname = "Times",
part = "body",
fontsize = 8,
iBase = 0,
bold = FALSE
)
Arguments
dataTable |
data.frame with data used in table, summary table for body or header data.frame for the header. |
ft |
Corresponding |
fontname |
String with font name, 'Times' by default. |
part |
string with part of the table to consider,
see |
fontsize |
Integer with font size, 8 by default. |
iBase |
Integer with base row index (if different than 0). |
bold |
Logical (FALSE by default) should the superscript/subscript be indicated in bold? |
Value
flextable
with superscript/subscript.
Author(s)
Laure Cougnaud
Format a percentage.
Description
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)
Usage
formatPercentage(x, nDec = 1)
Arguments
x |
Numeric vector with percentage(s) |
nDec |
Integer of length 1, number of decimals used to round the percentage, 1 by default. |
Value
String with formatted percentage
Author(s)
Laure Cougnaud
See Also
Other decimals:
getMaxNDecimals()
,
getMaxNDecimalsData()
,
getNDecimals()
,
getNDecimalsData()
Examples
xPerc <- c(NA, 0, 100, 99.95, 0.012, 34.768)
formatPercentage(x = xPerc)
Format summary statistics table for export
Description
Format summary statistics table for export
Usage
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 = "-"
)
Arguments
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. |
Value
summaryTable reformatted to wide format
Author(s)
Laure Cougnaud
Merge nested rows of a summary table
for a format compatible with flextable
Description
Merge nested rows of a summary table
for a format compatible with flextable
Usage
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
)
Arguments
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. |
Value
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.
Author(s)
Laure Cougnaud
Compute geometric coefficient of variation (in a scale from 0 to 100).
Description
The geometric coefficient of variation is computed as:
\sqrt{\exp(\sigma(log(x))^2)-1}*100
, with:
log: natural logarithm
\sigma
: standard deviation
Usage
geomCV(x, na.rm = FALSE)
Arguments
x |
Numeric vector. |
na.rm |
Logical, should NA value(s) be removed (FALSE by default)? |
Value
Numeric vector of length 1 with geometric coefficient of variation.
Author(s)
Laure Cougnaud
See Also
Other stats utility functions:
cv()
,
geomMean()
,
geomSD()
,
geomSE()
,
se()
Examples
# Geometric coefficient of variation of a sample from a log normal distribution:
geomCV(rlnorm(n = 1000, meanlog = 0, sdlog = 1))
Compute geometric mean.
Description
The geometric mean is computed as:
\exp(\bar{log(x)})
, with:
log: natural logarithm
\bar{log(x)}
: arithmetic mean of log(x)
Usage
geomMean(x, na.rm = FALSE)
Arguments
x |
Numeric vector. |
na.rm |
Logical, should NA value(s) be removed (FALSE by default)? |
Value
Numeric vector of length 1 with geometric mean.
Author(s)
Laure Cougnaud
See Also
Other stats utility functions:
cv()
,
geomCV()
,
geomSD()
,
geomSE()
,
se()
Examples
# 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))
Compute geometric standard deviation
Description
The geometric standard deviation is computed as:
\exp(\sigma(log(x)))
, with:
log: natural logarithm
\sigma
: standard deviation
Usage
geomSD(x, na.rm = FALSE)
Arguments
x |
Numeric vector. |
na.rm |
Logical, should NA value(s) be removed (FALSE by default)? |
Value
Numeric vector of length 1 with geometric mean.
Author(s)
Laure Cougnaud
See Also
Other stats utility functions:
cv()
,
geomCV()
,
geomMean()
,
geomSE()
,
se()
Examples
# geometric standard deviation of a sample from a log normal distribution:
geomSD(rlnorm(n = 1000, meanlog = 0, sdlog = 1))
Compute geometric standard error of the mean.
Description
The geometric standard error of the mean is computed as:
\exp(se(log(x)
, with:
log: natural logarithm
se
: standard error of the mean, as computed withse
Usage
geomSE(x, na.rm = FALSE)
Arguments
x |
Numeric vector. |
na.rm |
Logical, should NA value(s) be removed (FALSE by default)? |
Value
Numeric vector of length 1 with geometric standard error of the mean.
Author(s)
Laure Cougnaud
See Also
Other stats utility functions:
cv()
,
geomCV()
,
geomMean()
,
geomSD()
,
se()
Examples
# Geometric standard error of the mean of a sample from a log normal distribution:
geomSE(rlnorm(n = 1000, meanlog = 0, sdlog = 1))
Get specific attribute from a summaryTable or a list of summaryTables
Description
Get specific attribute from a summaryTable or a list of summaryTables
Usage
getAttribute(summaryTable, name, default = NULL)
Arguments
name |
String with attribute name. |
default |
Object with default value for attribute, NULL by default. |
Value
Object with attribute, or default
is doesn't
exists in summaryTable
Author(s)
Laure Cougnaud
Get color palette for the tables
Description
This function gets the color palettes for the tables specified as global options.
Usage
getColorPaletteTable(style = c("report", "presentation"))
Arguments
style |
String with style of report. Either 'report' or 'presentation'. By default, the style is 'report'. |
Details
By default, the function returns the palette of the package. The user can specify a custom palette by setting the global options.
Value
A named vector with hex colors.
Examples
# 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")
Get dimension of the page available for content for standard Word report or PowerPoint presentation.
Description
Report is in A4 and presentation dimensions extracted from PowerPoint. The returned dimensions are the page dimensions without the margins.
Usage
getDimPage(
type = c("width", "height"),
landscape = (style == "presentation"),
margin = 1,
pageDim = NULL,
style = "report"
)
Arguments
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' |
Value
numeric vector with dimension of interest,
in the same order as specified via the type
parameter.
Author(s)
Laure Cougnaud
Examples
## 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)
Format or create flextable for listings.
Description
Flextable version >= 0.4.7 and pandoc >= 2.4 is required to included such table in a Rmarkdown document.
Usage
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
)
Arguments
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 |
Value
flextable
with style.
Examples
# 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))
Get maximum number of decimals in a variable, based on pre-defined rule and/or data.
Description
The function getNDecimals
) extracts the number
of decimals in a specific variable.
Usage
getMaxNDecimals(x, ...)
Arguments
x |
Numeric vector. |
... |
Any parameters for the |
Value
Integer with maximum number of decimals in a character vector.
Author(s)
Laure Cougnaud
See Also
Other decimals:
formatPercentage()
,
getMaxNDecimalsData()
,
getNDecimals()
,
getNDecimalsData()
Examples
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)
Get maximum number of decimals in a variable based on the data
(getNDecimalsData
)
Description
Get maximum number of decimals in a variable based on the data
(getNDecimalsData
)
Usage
getMaxNDecimalsData(x)
Arguments
x |
Numeric vector. |
Value
Integer with maximum number of decimals in a character vector.
Author(s)
Laure Cougnaud x <- c(0.99, 5.679, 50.45, 1450) # extract max number of decimals based on data: getMaxNDecimalsData(x)
See Also
Other decimals:
formatPercentage()
,
getMaxNDecimals()
,
getNDecimals()
,
getNDecimalsData()
Get number of decimals for a specific vector.
Description
The number of decimals is extracted either:
from specific implemented rule : see
getNDecimalsRule
for further detailsfrom the data itself: see
getNDecimalsData
for further detailsboth criterias: in this case the minimum of the number of decimals for both criterias is used
Usage
getNDecimals(x, useRule = TRUE, rule = "1", useData = TRUE)
Arguments
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 |
Value
Numeric vector of same length than x
with the number of decimals.
Author(s)
Laure Cougnaud
See Also
Other decimals:
formatPercentage()
,
getMaxNDecimals()
,
getMaxNDecimalsData()
,
getNDecimalsData()
Examples
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).
Description
Get number of decimals based on the data in a numeric vector. Note: NA is returned if the element is missing (NA).
Usage
getNDecimalsData(x)
Arguments
x |
Numeric vector. |
Value
Numeric vector of same length than x
with the number of decimals.
Author(s)
Laure Cougnaud
See Also
Other decimals:
formatPercentage()
,
getMaxNDecimals()
,
getMaxNDecimalsData()
,
getNDecimals()
Examples
x <- c(0.99, 5.679, 50.45, 1450)
getNDecimalsData(x)
Get number of decimals based pre-defined rule(s).
Description
Note: NA is returned if the element is missing (NA).
Usage
getNDecimalsRule(x, rule = c("1"))
Arguments
x |
Numeric vector. |
rule |
Character vector with rule to use to derive the number of parameters. Currently only: '1' is implemented.
|
Value
Numeric vector of same length than x
with the number of decimals.
Author(s)
Laure Cougnaud
Examples
x <- c(0.99, 5.679, 50.45, 1450)
getNDecimalsRule(x = x)
Get position(s) (start, end) of a pattern in a string.
Description
Get position(s) (start, end) of a pattern in a string.
Usage
getPatternPosition(x, startPattern, endPattern = "\\}", format)
Arguments
x |
String. |
startPattern |
String with start pattern. |
endPattern |
String with end pattern. |
format |
String with type of formatting |
Value
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.
Author(s)
Laure Cougnaud
Compute custom statistics specified by the user.
Description
Compute custom statistics specified by the user.
Usage
getStatisticsSummaryStatisticsTable(
summaryTable,
statsVarInit,
var = NULL,
stats = NULL,
statsVarBy = NULL
)
Arguments
summaryTable |
Summary table. |
statsVarInit |
Character vector with initial statistics names. |
var |
Character vector with variable(s) of |
stats |
(Optionally) named list of expression or call object of summary statistics of interest. The names are reported in the header. The following variables are recognized, if the table is a:
If |
statsVarBy |
Character vector with colnames of
|
Value
List with two elements:
'summaryTable': summary table updated with statistics specified in
stats
'statsVar': Character vector with statistics names
Author(s)
Laure Cougnaud
Get default set of statistics for one particular variable.
Description
This set of statistics can be passed directly to the stats
parameter
of the of the package functions.
Usage
getStats(
type = "summary",
includeName = TRUE,
x = NULL,
nDecCont = getMaxNDecimals,
nDecN = 0,
nDecm = nDecN,
formatPercentage = inTextSummaryTable::formatPercentage
)
Arguments
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 |
Value
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.
Author(s)
Laure Cougnaud
See Also
Examples
## 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))
Get default set of statistics for variables of interest and specific dataset.
Description
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.
Usage
getStatsData(
data,
var = NULL,
type = "default",
extra = NULL,
args = NULL,
...
)
Arguments
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 |
Value
List with statistics to compute, named by var
Author(s)
Laure Cougnaud
See Also
Examples
# 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
Description
Get summary statistics table
Usage
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,
...
)
Arguments
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
|
Value
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
.
Author(s)
Laure Cougnaud
Common arguments for the functionalities of the inTextSummaryTable package for DT export.
Description
Common arguments for the functionalities of the inTextSummaryTable package for DT export.
Arguments
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 |
Value
No return value, used for the documentation of R functions for 'DT' output
Arguments used across the functions of the inTextSummaryTable package.
Description
Arguments used across the functions of the inTextSummaryTable package.
Arguments
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. |
Value
No return value, used for the documentation of R functions
Common arguments for the functionalities of the inTextSummaryTable package for flextable export.
Description
Common arguments for the functionalities of the inTextSummaryTable package for flextable export.
Arguments
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. |
Value
No return value, used for the documentation of R functions for 'flextable' output
Statistics in the in-text table package.
Description
In the in-text package, different set of statistics are available.
Details
The statistics are first computed as numeric ('Base statistics' section below), then formatted to be displayed in the table ('Formatted statistics' section below).
Value
No return value, used for the documentation of
the stats
parameter
Base statistics
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.
Formatted statistics
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 (ortype
parameter ofgetStats
).
These statistics are reported as text variables in the summary table (as data.frame), and typically displayed inside the final table.
Statistics formatting
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
ingetStatsData
).if the number of decimals is not specified:
a default format is set via theformatC
function.
statistics for counts:
number of subjects, records are rounded with the number of decimals specified via
nDecN
ornDecm
(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.
Description
Common arguments for the for the statistics utility functions of the inTextSummaryTable package.
Arguments
x |
Numeric vector. |
na.rm |
Logical, should NA value(s) be removed (FALSE by default)? |
Value
No return value, used for the documentation of stat utility R functions
Compute the interaction between variable(s),
without propagating the missing values (if present in one of the variable)
unlike the behaviour with interaction
.
This also ensure that the levels of the final interaction variables
are ordered similarly as the levels of the input var
(if present).
Description
Compute the interaction between variable(s),
without propagating the missing values (if present in one of the variable)
unlike the behaviour with interaction
.
This also ensure that the levels of the final interaction variables
are ordered similarly as the levels of the input var
(if present).
Usage
interactionCustom(data, var, varDataLevels = NULL)
Arguments
data |
Data.frame with data. |
var |
Character vector with variable(s) to consider. |
varDataLevels |
(optional) Data.frame with data to consider to define the levels of the variable. If not specified, only the combinations of variable(s) available in the data are retained. |
Value
list with:
'x': factor with interaction between the input
var
'dataLevels': data.frame with mapping between the
var
variable(s) and the new factor levels
Author(s)
Laure Cougnaud
Merge columns and rows in the header of a flextable object.
Description
This:
(1) for each row: checks that subsequent columns are identical (and corresponding sub-header overlap), so should be merged
(2) for each column: checks that subsequent rows are identical, so should be merged
filters cells planned to be merged across rows (2) if they are already merged across columns (1)
Usage
mergeHeaderCols(x, mapping)
Arguments
x |
a |
mapping |
a |
Value
Updated flextable object with merged cells in the header.
Page dimension for powerpoints
Description
Page dimension for powerpoints
Usage
pageDimPresentation
Format
An object of class numeric
of length 2.
Post-process the summary statistics table with variable flag.
Description
This function is for internal use within
the computeSummaryStatisticsTable
function.
Usage
postProcessVarFlag(summaryTable, varFlag)
Arguments
summaryTable |
Summary table as created internally in
|
varFlag |
Character vector, subset of |
Details
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'
Value
Summary table with
Author(s)
Laure Cougnaud
Compute standard error of the mean.
Description
The standard error of the mean is computed as:
\frac{\sigma(x)}{\sqrt{length(x)}}
, with:
\sigma(x)
: standard deviation of x
Usage
se(x, na.rm = FALSE)
Arguments
x |
Numeric vector. |
na.rm |
Logical, should NA value(s) be removed (FALSE by default)? |
Value
Numeric vector with standard error of the mean
Author(s)
Laure Cougnaud
See Also
Other stats utility functions:
cv()
,
geomCV()
,
geomMean()
,
geomSD()
,
geomSE()
Examples
se(rnorm(1000))
Smooth padding, e.g. remove padding bigger than 1
Description
Smooth padding, e.g. remove padding bigger than 1
Usage
smoothPadding(pad)
Arguments
pad |
Integer vector with padding. |
Value
Integer vector with 'smooth' padding.
Author(s)
Laure Cougnaud
Plot subject summary profile.
Description
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
).
Usage
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"),
...
)
Arguments
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 |
Value
ggplot
object or list of such
objects of byVar
is specified.
Author(s)
Laure Cougnaud
Plot a table with ggplot
of a text variable of interest.
Description
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.
Usage
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
)
Arguments
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. |
Value
ggplot
object
Author(s)
Laure Cougnaud and Michela Pasetto
summaryTable
Description
The summary statistics are computed in
computeSummaryStatisticsTable
, which creates asummaryTable
object.This object is exported to diverse formats via
export
Multiple summaryTable
objects are combined
together with combine.summaryTable
.
Details
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):
Iftype
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 ofstatPerc
'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 ofstatPercN
(or 'statPercm')'statm': number of records
computed statistics.
The statistics are stored in columns corresponding to names of thestatsVar
.
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' ifvarTotalInSepRow
'colVar': column name(s) of summary table with column variable included in the final table
'colTotalLab': label for the total
Value
Not relevant
Colors for tables in a presentation style
Description
Default colors are
header: white text on a blue background
body: black text on a grey background
footer: black text on a white background.
Usage
tableColorsPresentation
Format
An object of class character
of length 11.
Colors for tables in a report style
Description
Default colors are black text on a white background.
Usage
tableColorsReport
Format
An object of class character
of length 7.
Get unique variables with meaningful order.
Description
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 elementput
variableGroup
, if present, as last elementorder the unique elements based on the extracted order
Usage
uniqueVarWithOrder(...)
Arguments
... |
Lists |
Value
Vector with unique and ordered elements.
Author(s)
Laure Cougnaud
Custom function to write table to a text file
Description
This function is mainly a wrapper on write.table
,
with the specific options:
no rownames
no quoting
tab separator
Usage
writeTable(x, file, ...)
Arguments
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 |
Value
No returned value, the object x
is exported to the specified file
.
Author(s)
Laure Cougnaud