Title: | General Utility Functions for Analysis of Clinical Data |
---|---|
Description: | Utility functions to facilitate the import, the reporting and analysis of clinical data. Example datasets in 'SDTM' and 'ADaM' format, containing a subset of patients/domains from the 'CDISC Pilot 01 study' are also available as R datasets to demonstrate the package functionalities. |
Authors: | Laure Cougnaud [aut, cre], Michela Pasetto [aut], Arne De Roeck [rev] (tests), Open Analytics [cph] |
Maintainer: | Laure Cougnaud <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.0 |
Built: | 2025-02-11 04:58:55 UTC |
Source: | https://github.com/openanalytics/clinutils |
Check if specified variables are in the data. If they are not, they are removed from specified variables and a message is printed.
checkVarInData(var, data, label)
checkVarInData(var, data, label)
var |
Character vector with variables. |
data |
Data.frame with data. |
label |
String with label used in message. |
var
present in data
,
NULL if empty
Default color palette is the color-blind viridis palette.
See documentation of viridis
.
clinColors(n, alpha = 1, begin = 0, end = 1, direction = 1, option = "D")
clinColors(n, alpha = 1, begin = 0, end = 1, direction = 1, option = "D")
n |
The number of colors ( |
alpha |
The alpha transparency, a number in [0,1], see argument alpha in
|
begin |
The (corrected) hue in [0,1] at which the color map begins. |
end |
The (corrected) hue in [0,1] at which the color map ends. |
direction |
Sets the order of colors in the scale. If 1, the default, colors are ordered from darkest to lightest. If -1, the order of colors is reversed. |
option |
see similar parameter in |
The viridis
function.
A set of default linetypes are available as a vector.
clinLinetypes
clinLinetypes
An object of class character
of length 6.
A character vector of linetypes.
A set of default shapes are available as named vector.
clinShapes
clinShapes
An object of class integer
of length 24.
A numeric vector of shapes.
A set of default shapes are available as character vector.
clinShapesText
clinShapesText
An object of class character
of length 24.
A character vector of shapes.
Parameters for all palette functions for clinical visualizations.
n |
Integer of length 1, number of elements in palette. |
x |
Vector with elements used for palette.
If factor, the levels are used, otherwise the unique elements of the vector.
Missing values are automatically removed, excepted if
|
includeNA |
Logical (FALSE by default),
should NA elements be retained in the palette in case
|
Specific palettes used in clinUtils
.
Color palette for a standard CDISC Normal/Reference Range Indicator.
colorPaletteNRIND
colorPaletteNRIND
A named character vector with color for typical Normal Reference Range Indicator variable:
"LOW": orange
"NORMAL": green4
"HIGH": orange
"ABNORMAL": red
"UNKNOWN" or 'NA': grey
"NA": grey
Get differences between two data.frames
compareDiff( newData, oldData, referenceVars = intersect(colnames(newData), colnames(oldData)), changeableVars = NULL )
compareDiff( newData, oldData, referenceVars = intersect(colnames(newData), colnames(oldData)), changeableVars = NULL )
newData |
data.frame object representing the new data |
oldData |
data.frame object representing the old data |
referenceVars |
character vector of the columns in the data that are the used as
reference for the comparison. |
changeableVars |
character vector of the columns in the data for which you want to assess the change,
e.g. variables that might have changed from the old to the new data. |
Object of class 'diff.data', i.e. a data.frame with columns:
'Comparison type': type of difference between the old and new data, either:
'Change': records present both in new and old data, based on the reference variables, but with difference(s) in changeable vars
'Addition': records with reference variables present in new but not in old data
'Removal': records with reference variables present in old but not in new data
'Version': 'Previous' or 'Current' depending if record represents content from old or new data respectively
referenceVars
changeableVars
To identify the differences between datasets, the following steps are followed:
removal of records identical between the old and new dataset (will be considered as 'Identical' later on)
records with a reference value present in the old dataset but not in the new dataset are considered 'Removal'
records with a reference value present in the new dataset but not in the old dataset are considered 'Addition'
records with reference value present both in the new and old dataset, after filtering of identical records and with difference in the changeable variables are considered 'Change'
Laure Cougnaud
Compare tables
compareTables( newData, oldData, referenceVars = intersect(colnames(newData), colnames(oldData)), changeableVars = NULL, outputType = c("table-comparison", "newData-diff", "oldData-diff", "table-comparison-interactive", "newData-diff-interactive", "oldData-diff-interactive"), ... )
compareTables( newData, oldData, referenceVars = intersect(colnames(newData), colnames(oldData)), changeableVars = NULL, outputType = c("table-comparison", "newData-diff", "oldData-diff", "table-comparison-interactive", "newData-diff-interactive", "oldData-diff-interactive"), ... )
newData |
data.frame object representing the new data |
oldData |
data.frame object representing the old data |
referenceVars |
character vector of the columns in the data that are the used as
reference for the comparison. |
changeableVars |
character vector of the columns in the data for which you want to assess the change,
e.g. variables that might have changed from the old to the new data. |
outputType |
String describing which output should be returned, (multiple are possible), either:
|
... |
Any parameters passed to the |
One of the output types specified in outputType
.
By default, all outputs are returned.
If multiple output types are specified, a list of those are returned
(named by output type).
To identify the differences between datasets, the following steps are followed:
removal of records identical between the old and new dataset (will be considered as 'Identical' later on)
records with a reference value present in the old dataset but not in the new dataset are considered 'Removal'
records with a reference value present in the new dataset but not in the old dataset are considered 'Addition'
records with reference value present both in the new and old dataset, after filtering of identical records and with difference in the changeable variables are considered 'Change'
Laure Cougnaud, Michela Pasetto
## Example 1 # In this case the referenceVar 'a' is the same # the comparison highlights only as change in the variables 'c' and 'd' newData <- data.frame( "a" = c(1, 2, 3, 4), "b" = c(5, 6, 7, 8), "c" = rep(1, 4), "d" = rep(2, 4) ) oldData <- data.frame( "a" = c(1, 2, 3, 4), "b" = c(3, 4, 7, 8), "c" = rep(2, 4), "d" = rep(1, 4) ) compareTables( newData = newData, oldData = oldData, referenceVars = "a", changeableVars = c("c", "d") ) ## Example 2 # In this case the referenceVar 'a' changes in the last two rows # the comparison highlights as change the second and third rows in the variables 'c' and 'd' # whereas the last rows are additions/removals with respect to the reference 'a' newData <- data.frame( "a" = c(7, 1, 2, 3, 4), "b" = c(2, 1, 6, 7, 8), "c" = rep(1, 5), "d" = rep(2, 5) ) oldData <- data.frame( "a" = c(7, 1, 2, 5, 6), "b" = c(2, 3, 4, 7, 8), "c" = c(1, rep(2, 4)), "d" = c(2, rep(1, 4)) ) compareTables( newData = newData, oldData = oldData, referenceVars = "a", changeableVars = c("c", "d") ) ## Example 3 # In this case the referenceVar 'a' is the same # also the variable 'c' is the same and it's the only changeable var evaluated newData <- data.frame( "a" = c(1, 2, 3, 4), "b" = c(5, 6, 7, 8), "c" = rep(1, 4), "d" = rep(2, 4) ) oldData <- data.frame( "a" = c(1, 2, 3, 4), "b" = c(3, 4, 7, 8), "c" = rep(1, 4), "d" = rep(1, 4) ) compareTables( newData = newData, oldData = oldData, referenceVars = "a", changeableVars = "c" ) ## Not run: # due to time constraint in CRAN ## In case only a specific output should be returned: newData <- data.frame( "a" = c(7, 1, 2, 3, 4), "b" = c(2, 1, 6, 7, 8), "c" = rep(1, 5), "d" = rep(2, 5) ) oldData <- data.frame( "a" = c(7, 1, 2, 5, 6), "b" = c(2, 3, 4, 7, 8), "c" = c(1, rep(2, 4)), "d" = c(2, rep(1, 4)) ) # get only the differences between datasets: # as a data.frame compareTables(newData = newData, oldData = oldData, referenceVars = "a", changeableVars = c("c", "d"), outputType = "table-comparison") # as an interactive DataTable compareTables(newData = newData, oldData = oldData, referenceVars = "a", changeableVars = c("c", "d"), outputType = "table-comparison-interactive" ) # only the new data compareTables( newData = newData, oldData = oldData, referenceVars = "a", changeableVars = c("c", "d"), outputType = "newData-diff" ) # only the new data in interactive mode compareTables( newData = newData, oldData = oldData, referenceVars = "a", changeableVars = c("c", "d"), outputType = "newData-diff-interactive" ) # only the new data in static and interactive mode compareTables( newData = newData, oldData = oldData, referenceVars = "a", changeableVars = c("c", "d"), outputType = c("newData-diff", "newData-diff-interactive") ) # only the old data compareTables(newData = newData, oldData = oldData, referenceVars = "a", changeableVars = c("c", "d"), outputType = "oldData-diff" ) # only the old data in interactive mode compareTables( newData = newData, oldData = oldData, referenceVars = "a", changeableVars = c("c", "d"), outputType = "oldData-diff-interactive" ) # only the old data in static and interactive mode compareTables( newData = newData, oldData = oldData, referenceVars = "a", changeableVars = c("c", "d"), outputType = c("oldData-diff", "oldData-diff-interactive") ) ## End(Not run) ## no changeable vars newData <- data.frame( "a" = c(7, 1, 2, 3, 4), "b" = c(2, 1, 6, 7, 8), "c" = rep(1, 5), "d" = rep(2, 5) ) oldData <- data.frame( "a" = c(7, 1, 2, 5, 6), "b" = c(2, 3, 4, 7, 8), "c" = c(1, rep(2, 4)), "d" = c(2, rep(1, 4)) ) compareTables(newData = newData, oldData = oldData, referenceVars = "a" ) ## duplicated records # in case there are multiple records for the same reference variables, # identical records are flagged as 'Identity' and reported in the table # reporting differences; and the different record are flagged as 'Change', 'Addition' or 'Removal' newData <- data.frame( "a" = c(7, 7), "b" = c(1, 2), "c" = c(1, 2), "d" = c(2, 3) ) oldData <- data.frame( "a" = c(7, 7, 7), "b" = c(3, 4, 5), "c" = c(1, 3, 5), "d" = c(2, 4, 6) ) compareTables( newData = newData, oldData = oldData, referenceVars = "a", changeableVars = c("c", "d"), ) ## with labels in the interactive format, see ? getClinDT ## Not run: # due to time constraint in CRAN newData <- data.frame( "a" = c(7, 1, 2, 3, 4), "b" = c(2, 1, 6, 7, 8), "c" = rep(1, 5), "d" = rep(2, 5) ) oldData <- data.frame( "a" = c(7, 1, 2, 5, 6), "b" = c(2, 3, 4, 7, 8), "c" = c(1, rep(2, 4)), "d" = c(2, rep(1, 4)) ) compareTables( newData = newData, oldData = oldData, referenceVars = "a", changeableVars = c("c", "d"), # parameters passed to datatable colnames = c( "My reference variable" = "a", "Changeable variable c" = "c", "Changeable variable d" = "d" ) ) ## End(Not run)
## Example 1 # In this case the referenceVar 'a' is the same # the comparison highlights only as change in the variables 'c' and 'd' newData <- data.frame( "a" = c(1, 2, 3, 4), "b" = c(5, 6, 7, 8), "c" = rep(1, 4), "d" = rep(2, 4) ) oldData <- data.frame( "a" = c(1, 2, 3, 4), "b" = c(3, 4, 7, 8), "c" = rep(2, 4), "d" = rep(1, 4) ) compareTables( newData = newData, oldData = oldData, referenceVars = "a", changeableVars = c("c", "d") ) ## Example 2 # In this case the referenceVar 'a' changes in the last two rows # the comparison highlights as change the second and third rows in the variables 'c' and 'd' # whereas the last rows are additions/removals with respect to the reference 'a' newData <- data.frame( "a" = c(7, 1, 2, 3, 4), "b" = c(2, 1, 6, 7, 8), "c" = rep(1, 5), "d" = rep(2, 5) ) oldData <- data.frame( "a" = c(7, 1, 2, 5, 6), "b" = c(2, 3, 4, 7, 8), "c" = c(1, rep(2, 4)), "d" = c(2, rep(1, 4)) ) compareTables( newData = newData, oldData = oldData, referenceVars = "a", changeableVars = c("c", "d") ) ## Example 3 # In this case the referenceVar 'a' is the same # also the variable 'c' is the same and it's the only changeable var evaluated newData <- data.frame( "a" = c(1, 2, 3, 4), "b" = c(5, 6, 7, 8), "c" = rep(1, 4), "d" = rep(2, 4) ) oldData <- data.frame( "a" = c(1, 2, 3, 4), "b" = c(3, 4, 7, 8), "c" = rep(1, 4), "d" = rep(1, 4) ) compareTables( newData = newData, oldData = oldData, referenceVars = "a", changeableVars = "c" ) ## Not run: # due to time constraint in CRAN ## In case only a specific output should be returned: newData <- data.frame( "a" = c(7, 1, 2, 3, 4), "b" = c(2, 1, 6, 7, 8), "c" = rep(1, 5), "d" = rep(2, 5) ) oldData <- data.frame( "a" = c(7, 1, 2, 5, 6), "b" = c(2, 3, 4, 7, 8), "c" = c(1, rep(2, 4)), "d" = c(2, rep(1, 4)) ) # get only the differences between datasets: # as a data.frame compareTables(newData = newData, oldData = oldData, referenceVars = "a", changeableVars = c("c", "d"), outputType = "table-comparison") # as an interactive DataTable compareTables(newData = newData, oldData = oldData, referenceVars = "a", changeableVars = c("c", "d"), outputType = "table-comparison-interactive" ) # only the new data compareTables( newData = newData, oldData = oldData, referenceVars = "a", changeableVars = c("c", "d"), outputType = "newData-diff" ) # only the new data in interactive mode compareTables( newData = newData, oldData = oldData, referenceVars = "a", changeableVars = c("c", "d"), outputType = "newData-diff-interactive" ) # only the new data in static and interactive mode compareTables( newData = newData, oldData = oldData, referenceVars = "a", changeableVars = c("c", "d"), outputType = c("newData-diff", "newData-diff-interactive") ) # only the old data compareTables(newData = newData, oldData = oldData, referenceVars = "a", changeableVars = c("c", "d"), outputType = "oldData-diff" ) # only the old data in interactive mode compareTables( newData = newData, oldData = oldData, referenceVars = "a", changeableVars = c("c", "d"), outputType = "oldData-diff-interactive" ) # only the old data in static and interactive mode compareTables( newData = newData, oldData = oldData, referenceVars = "a", changeableVars = c("c", "d"), outputType = c("oldData-diff", "oldData-diff-interactive") ) ## End(Not run) ## no changeable vars newData <- data.frame( "a" = c(7, 1, 2, 3, 4), "b" = c(2, 1, 6, 7, 8), "c" = rep(1, 5), "d" = rep(2, 5) ) oldData <- data.frame( "a" = c(7, 1, 2, 5, 6), "b" = c(2, 3, 4, 7, 8), "c" = c(1, rep(2, 4)), "d" = c(2, rep(1, 4)) ) compareTables(newData = newData, oldData = oldData, referenceVars = "a" ) ## duplicated records # in case there are multiple records for the same reference variables, # identical records are flagged as 'Identity' and reported in the table # reporting differences; and the different record are flagged as 'Change', 'Addition' or 'Removal' newData <- data.frame( "a" = c(7, 7), "b" = c(1, 2), "c" = c(1, 2), "d" = c(2, 3) ) oldData <- data.frame( "a" = c(7, 7, 7), "b" = c(3, 4, 5), "c" = c(1, 3, 5), "d" = c(2, 4, 6) ) compareTables( newData = newData, oldData = oldData, referenceVars = "a", changeableVars = c("c", "d"), ) ## with labels in the interactive format, see ? getClinDT ## Not run: # due to time constraint in CRAN newData <- data.frame( "a" = c(7, 1, 2, 3, 4), "b" = c(2, 1, 6, 7, 8), "c" = rep(1, 5), "d" = rep(2, 5) ) oldData <- data.frame( "a" = c(7, 1, 2, 5, 6), "b" = c(2, 3, 4, 7, 8), "c" = c(1, rep(2, 4)), "d" = c(2, rep(1, 4)) ) compareTables( newData = newData, oldData = oldData, referenceVars = "a", changeableVars = c("c", "d"), # parameters passed to datatable colnames = c( "My reference variable" = "a", "Changeable variable c" = "c", "Changeable variable d" = "d" ) ) ## End(Not run)
General parameters used for the comparison table functionality
newData |
data.frame object representing the new data |
oldData |
data.frame object representing the old data |
referenceVars |
character vector of the columns in the data that are the used as
reference for the comparison. |
changeableVars |
character vector of the columns in the data for which you want to assess the change,
e.g. variables that might have changed from the old to the new data. |
diffData |
Object of class 'diff.data' containing
differences between datasets, as returned by the |
outputType |
String describing which output should be returned, (multiple are possible), either:
|
The comparison of the two input tables.
Convert a data frame into a data.table
object.
convertToDatatable(data)
convertToDatatable(data)
data |
A data.frame |
A data.table
object.
Convert character vector to date/time object
convertToDateTime( x, format = c("%Y-%m-%dT%H:%M", "%Y-%m-%d"), colName = NULL, verbose = TRUE )
convertToDateTime( x, format = c("%Y-%m-%dT%H:%M", "%Y-%m-%d"), colName = NULL, verbose = TRUE )
x |
character vector to convert to date/time |
format |
string with possible format(s) of the input date/time in the ADaM dataset.
If multiple are specified, each format is tested successively, until at least one
element in the input vector is converted with the specified format
(non missing, following the approach described in
the |
colName |
string with name of column, used in message (if any). |
verbose |
logical, if TRUE (by default) progress messages are printed during execution |
Vector of class POSIXct
Laure Cougnaud
This contains a subset of the CDISC Pilot 01 study dataset for:
a selected subset of subjects
a selected subset of domains:
subject-level ('adsl')
adverse event ('adae')
laboratory chemistry data('adlbc')
vital signs ('advs')
concomitant medications ('adcm')
efficacy:
ADAS-COG Data ('adqsadas'), containing one of the
primary endpoint: ADAS-Cog (11)
(Alzheimer's Disease Assessment Scale - Cognitive Subscale
CIBIC+ questionnaire data ('adqscibc'), containing one
of the primary endpoint: CIBIC+
(Video-referenced Clinician's Interview-based Impression of Change)
NPI-X Item data ('adqsnpix'), containing the secondary endpoint:
NPI-X
(Mean Revised Neuropsychiatric Inventory)
pharmacokinetic parameters ('adpp')
Please note that this dataset contains different sets
of subjects than the other example datasets.
This dataset was created following the ADaM Version 2.0 standard. This dataset contains the 'Modified and augmented version of cdiscpilot01' dataset.
List of data.frames containing the ADaM
dataset for each selected domain.
Labels for the different variables across datasets
is available via the labelVars
attribute.
Laure Cougnaud
Original (and entire) datasets are available in:
https://github.com/phuse-org/phuse-scripts/tree/master/data/adam/cdisc
See in particular the define.xml file
for further description of the
datasets and variables name.
This contains a subset of the CDISC original Pilot 01 study dataset for:
a selected subset of subjects
a selected subset of domains:
adverse event ('ae')
concomitant medications ('cm')
disposition ('ds')
demographics ('dm')
treatment exposure ('ex')
laboratory ('lb')
medical history ('mh')
questionnaire ('qs') - only:
ADAS-Cog (11) primary endpoint (QSTESTCD == 'ACTOT'
)
CIBIC+ primary endpoint (QSTESTCD == 'CIBIC'
)
NPI-X Item secondary endpoint (QSTESTCD == 'NPTOT'
)
demographics supplemental dataset ('suppdm')
subject visits ('sv')
vital signs ('vs')
This dataset was created following the SDTM Version 2 standard.
List of data.frames containing the SDTM
dataset for each selected domain.
Labels for the different variables across datasets
is available via the labelVars
attribute.
Laure Cougnaud
Original (and entire) datasets are available in:
https://github.com/phuse-org/phuse-scripts/tree/master/data/sdtm/cdiscpilot01
See in particular the define.xml file
for further description of the
datasets and variables name.
compareDiff
to a user-friendly formatExport the 'diff.data' object from compareDiff
to a user-friendly format
exportDiffData( diffData, newDataDiff, oldDataDiff, referenceVars = attr(diffData, "referenceVars"), changeableVars = attr(diffData, "changeableVars"), to = "DT", ... )
exportDiffData( diffData, newDataDiff, oldDataDiff, referenceVars = attr(diffData, "referenceVars"), changeableVars = attr(diffData, "changeableVars"), to = "DT", ... )
diffData |
Object of class 'diff.data' containing
differences between datasets, as returned by the |
newDataDiff |
data.frame with new data with differences
as returned by the |
oldDataDiff |
data.frame with old data with differences
as returned by the |
referenceVars |
character vector of the columns in the data that are the used as
reference for the comparison. |
changeableVars |
character vector of the columns in the data for which you want to assess the change,
e.g. variables that might have changed from the old to the new data. |
to |
String with export format,
currently only: |
... |
Extra parameters besides 'data' and 'nonVisibleVars',
currently passed to the |
Depending on the to
parameter:
'DT': a datatable
with the difference between datasets,
with:
highlighting depending on the difference between datasets:
'Addition' in green
'Removal' in yellow
'Change' in lightblue
'Identical' are not highlighted
records only present in the old dataset are displayed in italic
Format details comparison
formatDetailsComparison( diffData, referenceVars = attr(diffData, "referenceVars"), changeableVars = attr(diffData, "changeableVars") )
formatDetailsComparison( diffData, referenceVars = attr(diffData, "referenceVars"), changeableVars = attr(diffData, "changeableVars") )
diffData |
Object of class 'diff.data' containing
differences between datasets, as returned by the |
referenceVars |
character vector of the columns in the data that are the used as
reference for the comparison. |
changeableVars |
character vector of the columns in the data for which you want to assess the change,
e.g. variables that might have changed from the old to the new data. |
diffData
with extra columns:
'[].diff' for the referenceVars
and changeableVars
columns, and attributes: 'colsDiff' as a named vector
with mapping with input variables (names) and corresponding
diff variables.
Laure Cougnaud
datatable
as a barplot.Format a variable in a datatable
as a barplot.
formatDTBarVar( tableDT, data, barVar = NULL, barColorThr = NULL, barRange = NULL, getCol = function(x) x )
formatDTBarVar( tableDT, data, barVar = NULL, barColorThr = NULL, barRange = NULL, getCol = function(x) x )
tableDT |
|
data |
Data.frame with content of |
barVar |
Character vector with numeric variable of |
barColorThr |
Numeric vector with threshold to consider to color the bar, either:
|
barRange |
(optional) range for the bars, either:
If not specified, the range of each |
getCol |
Function, which for an index of a column
in |
Updated tableDT
Laure Cougnaud
This function concatenates and formats text strings to a label e.g to use for chunk and table/figures
formatLabel(...)
formatLabel(...)
... |
string(s) to be concatenated to form label or data.frame with only one row. If an unique data.frame is specified, the different columns are collapsed to form one label. |
String with chunk label
Laure Cougnaud
Concatenate and format text strings to a chunk label
formatLabelChunk(...)
formatLabelChunk(...)
... |
string to be concatenated to form chunk label |
String with chunk label
Laure Cougnaud
This function formats a variable with long labels by wrapping its elements into multiple lines.
formatLongLabel(x, width = 20)
formatLongLabel(x, width = 20)
x |
character vector with labels to format |
width |
target maximum size. Note: a word
longer that this width won't be split (see |
Vector with formatted labels
Laure Cougnaud longLabel <- "This is a very long description of the variable in the dataset" cat(longLabel) cat(formatLongLabel(longLabel))
This function concatenates and formats
text strings to a label of a table for bookdown
package
formatTableLabel(...)
formatTableLabel(...)
... |
string to be concatenated to form label |
String with chunk label
Laure Cougnaud
The following workflow is used:
format the variable as a factor
wrap it across multiple lines if needed
sort (its levels) according to a grouping variable
formatVarForPlotLabel( data, paramVar = NULL, paramGroupVar = NULL, revert = FALSE, width = 20 )
formatVarForPlotLabel( data, paramVar = NULL, paramGroupVar = NULL, revert = FALSE, width = 20 )
data |
data.frame with data |
paramVar |
string, variable of |
paramGroupVar |
(optional) character vector with variable(s) of
|
revert |
logical, if TRUE revert the order of the levels of the variable |
width |
max number of characters in the |
Vector with re-formatted paramVar
, NULL if empty
Laure Cougnaud library(ggplot2) data(dataADaMCDISCP01) dataAE <- dataADaMCDISCP01$ADAE
# by default, groups are sorted alphabetically in ggplot2 (from bottom to top for an histogram) ggplot(data = dataAE, aes(y = AEDECOD, fill = AEBODSYS)) + geom_histogram(stat="count")
# by default: labels are set to a new line if more than 20 characters: dataAE$AEDECOD <- formatVarForPlotLabel(data = dataAE, paramVar = "AEDECOD") levels(dataAE$AEDECOD) ggplot(data = dataAE, aes(y = AEDECOD, fill = AEBODSYS)) + geom_histogram(stat="count")
# revert order of the variable dataAE$AEDECOD <- formatVarForPlotLabel(data = dataAE, paramVar = "AEDECOD", revert = TRUE) levels(dataAE$AEDECOD) ggplot(data = dataAE, aes(y = AEDECOD, fill = AEBODSYS)) + geom_histogram(stat="count")
# group based on body system dataAE$AEDECOD <- formatVarForPlotLabel(data = dataAE, paramVar = "AEDECOD", paramGroupVar = "AEBODSYS") ggplot(data = dataAE, aes(y = AEDECOD, fill = AEBODSYS)) + geom_histogram(stat="count")
This function converts a data.frame
from R into
a datatable
object
with sensitive defaults.
Extra functionalities are available to:
have columns or cells of interest that are collapsible/expandable
(see expandVar
/expandIdx
)
group rows based on a variable (see rowGroupVar
)
display a variable as barplot (with specified range of threshold)
(see barVar
)
hide variable(s) (see nonVisibleVar
)
getClinDT( data, nonVisibleVar = NULL, nonVisible = NULL, percVar = NULL, barVar = NULL, barColorThr = NULL, barRange = NULL, filter = "top", searchBox = FALSE, pageLength, fixedColumns = NULL, columnsWidth = NULL, options = list(), expandVar = NULL, expandIdx = NULL, escape = TRUE, rowGroup = NULL, rowGroupVar = NULL, vAlign = "top", callback = NULL, buttons = getClinDTButtons(), scrollX = TRUE, file = NULL, verbose = TRUE, ... )
getClinDT( data, nonVisibleVar = NULL, nonVisible = NULL, percVar = NULL, barVar = NULL, barColorThr = NULL, barRange = NULL, filter = "top", searchBox = FALSE, pageLength, fixedColumns = NULL, columnsWidth = NULL, options = list(), expandVar = NULL, expandIdx = NULL, escape = TRUE, rowGroup = NULL, rowGroupVar = NULL, vAlign = "top", callback = NULL, buttons = getClinDTButtons(), scrollX = TRUE, file = NULL, verbose = TRUE, ... )
data |
Data.frame, matrix or |
nonVisibleVar |
Character vector with column(s) in |
nonVisible |
This parameter is deprecated, use the new interface
with the |
percVar |
Character vector with percentage columns. These columns should contain the percentage from 0 to 1. The content of these colunms will be rounded to 2 digits. |
barVar |
Character vector with numeric variable of |
barColorThr |
Numeric vector with threshold to consider to color the bar, either:
|
barRange |
(optional) range for the bars, either:
If not specified, the range of each |
filter |
String with position of the filter boxes
( |
searchBox |
Logical, if TRUE (FALSE by default) a general search box is included. |
pageLength |
Numeric with number of records to include in one page, by default set to 10. Set to Inf to include all records. |
fixedColumns |
List with fixed columns, see corresponding
parameter in the |
columnsWidth |
Character vector with column width,
of length 1 (used for all columns) or of length: |
options |
List with additional |
expandVar |
Character vector with expandable variables of |
expandIdx |
Matrix named with: 'row'/'column' containing row/column indices to expand. |
escape |
Column(s) to escape in the table
(e.g. containing raw HTML code), either character, numeric or logical of length 1.
See corresponding parameter in the |
rowGroup |
This parameter is deprecated, please use |
rowGroupVar |
Character vector with colname(s) of |
vAlign |
String with vertical alignment for the cells, 'top' by default. |
callback |
String with custom Javascript callback function. |
buttons |
DataTable buttons
(passed to the 'buttons' element of the |
scrollX |
Logical, if TRUE (by default) a horizontal scrolling bar
is included.
Note: this differs from the |
file |
(optional) String with name of html file to which the created DT should be exported. |
verbose |
Logical, if TRUE (by default) informative messages
are displayed, e.g. if specified |
... |
Additional parameters for the |
A datatable
object.
Laure Cougnaud
data(dataADaMCDISCP01) labelVars <- attr(dataADaMCDISCP01, "labelVars") # example of simple adverse event table dataAE <- dataADaMCDISCP01$ADAE subjectsSafety <- subset(dataADaMCDISCP01$ADSL, SAFFL == "Y")$USUBJID # compute counts of subjects presenting each AE tableAE <- stats::aggregate( USUBJID ~ AESOC:AEDECOD, data = dataAE, FUN = function(usubjid) length(unique(usubjid)) ) colnames(tableAE)[colnames(tableAE) == "USUBJID"] <- "N" # and percentages tableAE$perc <- round(tableAE$N/length(subjectsSafety)*100, 3) # sort records in decreasing percentage tableAE <- tableAE[order(tableAE$perc, decreasing = TRUE), ] # extract new variables labels tableAELabels <- getLabelVar( var = colnames(tableAE), labelVars = labelVars, label = c(N = '# subjects', perc = "% subjects") ) # 'colnames' for DT should be specified as c('new name' = 'old name', ...) tableAELabelsDT <- setNames(names(tableAELabels), tableAELabels) ## create table with bar # default: getClinDT( data = tableAE, barVar = "perc", colnames = tableAELabelsDT ) # specify range for the bar getClinDT( data = tableAE, filter = "none", barVar = "perc", barRange = c(0, 100), colnames = tableAELabelsDT ) # change color according to threshold getClinDT( data = tableAE, filter = "none", barVar = "perc", barColorThr = seq(from = 0, to = 100, by = 25), colnames = tableAELabelsDT ) ## group per system organ class (and decreasing N): tableAESOC <- aggregate(N ~ AESOC, data = tableAE, FUN = sum) tableAE$AESOC <- factor(tableAE$AESOC, levels = tableAESOC[order(tableAESOC$N, decreasing = FALSE), "AESOC"] ) tableAE <- tableAE[order(tableAE$AESOC, tableAE$perc, decreasing = TRUE), ] getClinDT( data = tableAE, filter = "none", barVar = "perc", barRange = c(0, 100), colnames = tableAELabelsDT, rowGroupVar = "AESOC", pageLength = Inf ) # expand the subject ID column, will # be accessible when clicking on the '+' button # Format URL correctly with: 'escape', # please note that indexing starts at 0! getClinDT( data = tableAE, barVar = "perc", colnames = tableAELabelsDT, expandVar = "USUBJID", escape = grep("USUBJID", colnames(tableAE))-1 ) # fix size for columns getClinDT( data = tableAE, colnames = tableAELabelsDT, fixedColumns = list(leftColumns = 1), columnsWidth = c(0.1, 0.7, 0.1, 0.1), width = "350px" # change dimension table ) ## Not run: # due to time constraint in CRAN # change default buttons getClinDT( data = tableAE, colnames = tableAELabelsDT, # remove general filter filter = "none", # custom set of buttons buttons = getClinDTButtons(type = c("csv", "excel", "pdf")) ) # add button to select columns getClinDT( data = tableAE, colnames = tableAELabelsDT, # custom set of buttons buttons = getClinDTButtons(typeExtra = "colvis") ) # export pdf in landscape format buttons <- getClinDTButtons( opts = list(pdf = list(orientation = "landscape")) ) getClinDT( data = tableAE, colnames = tableAELabelsDT, # custom set of buttons buttons = buttons ) # hide the first column: getClinDT( data = tableAE, nonVisibleVar = "AESOC" ) # with specific caption library(htmltools) caption <- tags$caption( "Number of subjects with adverse events grouped by system organ class.", br(), paste( "Percentages are based on the total number of patients having", "received a first study treatment." ) ) getClinDT( data = tableAE, filter = "none", barVar = "perc", barRange = c(0, 100), pageLength = Inf, colnames = tableAELabelsDT, rowGroupVar = "AESOC", caption = caption ) ## End(Not run)
data(dataADaMCDISCP01) labelVars <- attr(dataADaMCDISCP01, "labelVars") # example of simple adverse event table dataAE <- dataADaMCDISCP01$ADAE subjectsSafety <- subset(dataADaMCDISCP01$ADSL, SAFFL == "Y")$USUBJID # compute counts of subjects presenting each AE tableAE <- stats::aggregate( USUBJID ~ AESOC:AEDECOD, data = dataAE, FUN = function(usubjid) length(unique(usubjid)) ) colnames(tableAE)[colnames(tableAE) == "USUBJID"] <- "N" # and percentages tableAE$perc <- round(tableAE$N/length(subjectsSafety)*100, 3) # sort records in decreasing percentage tableAE <- tableAE[order(tableAE$perc, decreasing = TRUE), ] # extract new variables labels tableAELabels <- getLabelVar( var = colnames(tableAE), labelVars = labelVars, label = c(N = '# subjects', perc = "% subjects") ) # 'colnames' for DT should be specified as c('new name' = 'old name', ...) tableAELabelsDT <- setNames(names(tableAELabels), tableAELabels) ## create table with bar # default: getClinDT( data = tableAE, barVar = "perc", colnames = tableAELabelsDT ) # specify range for the bar getClinDT( data = tableAE, filter = "none", barVar = "perc", barRange = c(0, 100), colnames = tableAELabelsDT ) # change color according to threshold getClinDT( data = tableAE, filter = "none", barVar = "perc", barColorThr = seq(from = 0, to = 100, by = 25), colnames = tableAELabelsDT ) ## group per system organ class (and decreasing N): tableAESOC <- aggregate(N ~ AESOC, data = tableAE, FUN = sum) tableAE$AESOC <- factor(tableAE$AESOC, levels = tableAESOC[order(tableAESOC$N, decreasing = FALSE), "AESOC"] ) tableAE <- tableAE[order(tableAE$AESOC, tableAE$perc, decreasing = TRUE), ] getClinDT( data = tableAE, filter = "none", barVar = "perc", barRange = c(0, 100), colnames = tableAELabelsDT, rowGroupVar = "AESOC", pageLength = Inf ) # expand the subject ID column, will # be accessible when clicking on the '+' button # Format URL correctly with: 'escape', # please note that indexing starts at 0! getClinDT( data = tableAE, barVar = "perc", colnames = tableAELabelsDT, expandVar = "USUBJID", escape = grep("USUBJID", colnames(tableAE))-1 ) # fix size for columns getClinDT( data = tableAE, colnames = tableAELabelsDT, fixedColumns = list(leftColumns = 1), columnsWidth = c(0.1, 0.7, 0.1, 0.1), width = "350px" # change dimension table ) ## Not run: # due to time constraint in CRAN # change default buttons getClinDT( data = tableAE, colnames = tableAELabelsDT, # remove general filter filter = "none", # custom set of buttons buttons = getClinDTButtons(type = c("csv", "excel", "pdf")) ) # add button to select columns getClinDT( data = tableAE, colnames = tableAELabelsDT, # custom set of buttons buttons = getClinDTButtons(typeExtra = "colvis") ) # export pdf in landscape format buttons <- getClinDTButtons( opts = list(pdf = list(orientation = "landscape")) ) getClinDT( data = tableAE, colnames = tableAELabelsDT, # custom set of buttons buttons = buttons ) # hide the first column: getClinDT( data = tableAE, nonVisibleVar = "AESOC" ) # with specific caption library(htmltools) caption <- tags$caption( "Number of subjects with adverse events grouped by system organ class.", br(), paste( "Percentages are based on the total number of patients having", "received a first study treatment." ) ) getClinDT( data = tableAE, filter = "none", barVar = "perc", barRange = c(0, 100), pageLength = Inf, colnames = tableAELabelsDT, rowGroupVar = "AESOC", caption = caption ) ## End(Not run)
Get a default set of buttons to be included in the interactive table for clinical data.
getClinDTButtons( type = c("copy", "csv", "excel", "pdf", "print"), typeExtra = NULL, opts = NULL )
getClinDTButtons( type = c("copy", "csv", "excel", "pdf", "print"), typeExtra = NULL, opts = NULL )
type |
Character vector with type of buttons, among:
|
typeExtra |
Character vector with type of button(s) that should be added to the default set of buttons. |
opts |
List with extra opts for specific buttons. The list should be named with the button type. |
The 'colvis' button doesn't display
the non visible columns.
These are defined internally with:
options = list( columnDefs = list( list(targets = [X], className = 'noVis') ) )
with [X] the index of the column(s) in Javascript notation (starting from 0)
Nested list with default buttons
to be passed on to 'buttons' option in
the getClinDT
.
Laure Cougnaud
Get a color palette of specified length, either from a vector of names for the palette, or from a specified length.
getColorPalette(n = NULL, x = NULL, includeNA = FALSE, palette = clinColors)
getColorPalette(n = NULL, x = NULL, includeNA = FALSE, palette = clinColors)
n |
Integer of length 1, number of elements in palette. |
x |
Vector with elements used for palette.
If factor, the levels are used, otherwise the unique elements of the vector.
Missing values are automatically removed, excepted if
|
includeNA |
Logical (FALSE by default),
should NA elements be retained in the palette in case
|
palette |
A vector of custom colors,
or a function returning this vector from a specific
number of colors. |
Vector of colors,
named with the elements in x
if x
is specified.
Laure Cougnaud and Michela Pasetto
# extract longest palette available getColorPalette(n = 11) # extract palette for a vector getColorPalette(x = paste('treatment', 1:4)) # possibility to include missing values: getColorPalette(x = c(NA_character_, "group1"), includeNA = FALSE) getColorPalette(x = c(NA_character_, "group1"), includeNA = TRUE) # change default settings getColorPalette(n = 3, palette = c("red", "green", "grey"))
# extract longest palette available getColorPalette(n = 11) # extract palette for a vector getColorPalette(x = paste('treatment', 1:4)) # possibility to include missing values: getColorPalette(x = c(NA_character_, "group1"), includeNA = FALSE) getColorPalette(x = c(NA_character_, "group1"), includeNA = TRUE) # change default settings getColorPalette(n = 3, palette = c("red", "green", "grey"))
This function gets the labele for a parameter code extracted from the 'PARAM' column.
getLabelParamcd(paramcd, data, paramcdVar = "PARAMCD", paramVar = "PARAM")
getLabelParamcd(paramcd, data, paramcdVar = "PARAMCD", paramVar = "PARAM")
paramcd |
Character vector with parameter code(s). |
data |
Data.frame with data. |
paramcdVar |
String with column containing the |
paramVar |
String with column containing the |
Named character vector with label for parameter code or
paramcd
if label is missing.
Laure Cougnaud
# for ADaM data(dataADaMCDISCP01) getLabelParamcd(paramcd = "CHOL", data = dataADaMCDISCP01$ADLBC) # for SDTM data(dataSDTMCDISCP01) getLabelParamcd( paramcd = "ALB", data = dataSDTMCDISCP01$LB, paramcdVar = "LBTESTCD", paramVar = "LBTEST" )
# for ADaM data(dataADaMCDISCP01) getLabelParamcd(paramcd = "CHOL", data = dataADaMCDISCP01$ADLBC) # for SDTM data(dataSDTMCDISCP01) getLabelParamcd( paramcd = "ALB", data = dataSDTMCDISCP01$LB, paramcdVar = "LBTESTCD", paramVar = "LBTEST" )
The label is extracted either (in this order):
if label
is specified: from this label based on names,
or directly from this label if label
and var
are of length 1
(if available)
if labelVars
is specified: from the specified vector of labels,
based on names (if available)
if data
is specified: from the 'label' attribute
of the corresponding column in data
(if available)
If the label is not available, the input variable is returned.
getLabelVar(var, data = NULL, labelVars = NULL, label = NULL)
getLabelVar(var, data = NULL, labelVars = NULL, label = NULL)
var |
Character vector with variables of interest. |
data |
Data.frame with data. |
labelVars |
Named character vector with variable labels (names are the variable code),
usually extracted from |
label |
(Named) Character vector with user-specified label for |
Named character vector with label, var
is no label is available
Laure Cougnaud
data(dataADaMCDISCP01) labelVars <- attr(dataADaMCDISCP01, "labelVars") # (upon reading the data with haven: attributes should directly available in each column) getLabelVar(data = dataADaMCDISCP01, var = "AEREL") # but if the data as data.frame is subsetted, label is lost # so better to use 'labelVars': getLabelVar(var = "AEREL", labelVars = labelVars)
data(dataADaMCDISCP01) labelVars <- attr(dataADaMCDISCP01, "labelVars") # (upon reading the data with haven: attributes should directly available in each column) getLabelVar(data = dataADaMCDISCP01, var = "AEREL") # but if the data as data.frame is subsetted, label is lost # so better to use 'labelVars': getLabelVar(var = "AEREL", labelVars = labelVars)
Get label of the variables in SAS dataset(s)
getLabelVars(data, labelVars = NULL)
getLabelVars(data, labelVars = NULL)
data |
Data.frame with SAS dataset(s) or list of those. |
labelVars |
(optional) Named character vector with additional labels. |
Named vector with variable labels.
Laure Cougnaud
data(dataADaMCDISCP01) labelVars <- attr(dataADaMCDISCP01, "labelVars") # extract label for all variables from specified datasets: getLabelVars(data = dataADaMCDISCP01[c("ADLBC", "ADVS")], labelVars = labelVars) # extracted from specified labelVars, e.g. to specify custom label for specific variable(s) labelVarsCustom <- getLabelVars( data = dataADaMCDISCP01, labelVars = c(USUBJID = "Subject identifier for my study") ) labelVarsCustom["USUBJID"]
data(dataADaMCDISCP01) labelVars <- attr(dataADaMCDISCP01, "labelVars") # extract label for all variables from specified datasets: getLabelVars(data = dataADaMCDISCP01[c("ADLBC", "ADVS")], labelVars = labelVars) # extracted from specified labelVars, e.g. to specify custom label for specific variable(s) labelVarsCustom <- getLabelVars( data = dataADaMCDISCP01, labelVars = c(USUBJID = "Subject identifier for my study") ) labelVarsCustom["USUBJID"]
Get a linetype palette of specified length, either from a vector of names for the palette, or from a specified length.
getLinetypePalette( n = NULL, x = NULL, includeNA = FALSE, palette = clinLinetypes )
getLinetypePalette( n = NULL, x = NULL, includeNA = FALSE, palette = clinLinetypes )
n |
Integer of length 1, number of elements in palette. |
x |
Vector with elements used for palette.
If factor, the levels are used, otherwise the unique elements of the vector.
Missing values are automatically removed, excepted if
|
includeNA |
Logical (FALSE by default),
should NA elements be retained in the palette in case
|
palette |
A vector of custom linetypes,
or a function returning this vector from a specific
number of linetypes. |
Note that 7 unique symbols are available at maximum (replicated if necessary).
Vector with linetypes,
named with the elements in x
if x
is specified.
Laure Cougnaud and Michela Pasetto
# extract longest linetype palette available getLinetypePalette(n = 6) # extract palette for a vector getLinetypePalette(x = paste('treatment', 1:4)) # include missing getLinetypePalette(x = c(NA_character_, "group1"), includeNA = TRUE) getLinetypePalette(x = c(NA_character_, "group1"), includeNA = FALSE) # set custom linetypes lty <- getColorPalette(n = 3, palette = c("twodash", "dashed"))
# extract longest linetype palette available getLinetypePalette(n = 6) # extract palette for a vector getLinetypePalette(x = paste('treatment', 1:4)) # include missing getLinetypePalette(x = c(NA_character_, "group1"), includeNA = TRUE) getLinetypePalette(x = c(NA_character_, "group1"), includeNA = FALSE) # set custom linetypes lty <- getColorPalette(n = 3, palette = c("twodash", "dashed"))
The extraction of the palette elements is case-insensitive.
getPaletteCDISC(x, var, type, palette = NULL)
getPaletteCDISC(x, var, type, palette = NULL)
x |
Character vector of factor with
variable to consider.
The palette is built based on the unique elements
of this vector, or levels if |
var |
String with type of variable, among:
|
type |
String with type of palette:
|
palette |
(optional) Named vector with extra palette, e.g. to specify elements for non-standard categories. This palette is combined with the standard palette. |
The order of the palette depends on the type of the input
variable (x
):
if a factor is specified, the palette is ordered based on its levels
if a character vector is specified, the elements from the internal standard palette are used first, the remaining elements are then sorted alphabetically.
Named vector with palette.
Laure Cougnaud
## palette for reference range indicator variables xRIND <- c("LOW", "HIGH", "NORMAL", "NORMAL", "NORMAL", "ABNORMAL") # get standard palette getPaletteCDISC(x = xRIND, var = "NRIND", type = "shape") getPaletteCDISC(x = xRIND, var = "NRIND", type = "color") # in case extra categories are specified: xRIND <- c(xRIND, "High Panic") # the symbols are set to numeric symbols getPaletteCDISC(xRIND, var = "NRIND", type = "shape") # use shapePalette to specify symbols for extra categories getPaletteCDISC(xRIND, var = "NRIND", type = "shape", palette = c("High Panic" = "\u2666")) # palette is case-insensitive xRIND <- c("Low", "High", "Normal", "Normal", "Normal") getPaletteCDISC(xRIND, var = "NRIND", type = "shape")
## palette for reference range indicator variables xRIND <- c("LOW", "HIGH", "NORMAL", "NORMAL", "NORMAL", "ABNORMAL") # get standard palette getPaletteCDISC(x = xRIND, var = "NRIND", type = "shape") getPaletteCDISC(x = xRIND, var = "NRIND", type = "color") # in case extra categories are specified: xRIND <- c(xRIND, "High Panic") # the symbols are set to numeric symbols getPaletteCDISC(xRIND, var = "NRIND", type = "shape") # use shapePalette to specify symbols for extra categories getPaletteCDISC(xRIND, var = "NRIND", type = "shape", palette = c("High Panic" = "\u2666")) # palette is case-insensitive xRIND <- c("Low", "High", "Normal", "Normal", "Normal") getPaletteCDISC(xRIND, var = "NRIND", type = "shape")
Get only additions and removals from two data sets
(data.table
objects).
The additions/removals are extracted as x
vs
y
.
This function assumes that the objects x
and y
don't share identical rows.
getSetDiff(x, y, referenceVars)
getSetDiff(x, y, referenceVars)
x |
A |
y |
A |
referenceVars |
character vector of the columns in the data that are the used as
reference for the comparison. |
A data.table
object with the
additions/removals with respect of the comparison
between x
vs y
.
Get a shape palette of specified length, either from a vector of names for the palette, or from a specified length.
getShapePalette( n = NULL, x = NULL, includeNA = FALSE, asText = FALSE, palette = if (asText) { clinShapesText } else { clinShapes } )
getShapePalette( n = NULL, x = NULL, includeNA = FALSE, asText = FALSE, palette = if (asText) { clinShapesText } else { clinShapes } )
n |
Integer of length 1, number of elements in palette. |
x |
Vector with elements used for palette.
If factor, the levels are used, otherwise the unique elements of the vector.
Missing values are automatically removed, excepted if
|
includeNA |
Logical (FALSE by default),
should NA elements be retained in the palette in case
|
asText |
Logical (FALSE by default), should the palette be expressed as integer (base R plot and ggplot2 compatible) or in text format (e.g. required if combined with unicode symbols in ggplot2)? |
palette |
A vector of custom shapes,
or a function returning this vector from a specific
number of shapes. |
Note that 19 unique symbols are available at maximum (replicated if necessary).
Vector of shapes,
named with the elements in x
if x
is specified.
Laure Cougnaud and Michela Pasetto
#' extract longest shape palette available getShapePalette(n = 19) # extract palette for a vector getShapePalette(x = paste('treatment', 1:4)) # include missing getShapePalette(x = c(NA_character_, "group1"), includeNA = TRUE) getShapePalette(x = c(NA_character_, "group1"), includeNA = FALSE) # change default settings getShapePalette(x = paste('treatment', 1:3), palette = c("circle", "triangle")) # get symbols as 'text' (e.g. to be combined with Unicode in ggplot2) getShapePalette(x = paste('treatment', 1:4), asText = TRUE)
#' extract longest shape palette available getShapePalette(n = 19) # extract palette for a vector getShapePalette(x = paste('treatment', 1:4)) # include missing getShapePalette(x = c(NA_character_, "group1"), includeNA = TRUE) getShapePalette(x = c(NA_character_, "group1"), includeNA = FALSE) # change default settings getShapePalette(x = paste('treatment', 1:3), palette = c("circle", "triangle")) # get symbols as 'text' (e.g. to be combined with Unicode in ggplot2) getShapePalette(x = paste('treatment', 1:4), asText = TRUE)
Each object is included (internally) in a separated chunk, so different chunk options can be set for each object.
knitPrintListObjects( xList, generalLabel = "objectsList", labels = paste0(generalLabel, seq_along(xList)), titles = NULL, titleLevel = 2, printObject = FALSE, ... )
knitPrintListObjects( xList, generalLabel = "objectsList", labels = paste0(generalLabel, seq_along(xList)), titles = NULL, titleLevel = 2, printObject = FALSE, ... )
xList |
List of objects to print. |
generalLabel |
String with general label for the chunks,
used to build the |
labels |
Character vector with labels,
one for each chunk. |
titles |
Character vector with section titles, one for each chunk. |
titleLevel |
Integer with level for section header, 1 for top-level section header. |
printObject |
Logical, if TRUE (FALSE by default),
each object within |
... |
any |
This function should be called within a chunk
with the following option: results = 'asis'
.
No returned value, a text is printed with chunk content
Laure Cougnaud
## Not run: # Note: the following code should be included # within a chunk of a knitr (e.g. RMarkdown) document # to include a list of objects in the Rmarkdown output # list of flextable objects library(flextable) listTables <- list(flextable(iris), flextable(cars)) knitPrintListObjects( xList = listTables, titles = c("Iris dataset", "Cars dataset") ) ## End(Not run)
## Not run: # Note: the following code should be included # within a chunk of a knitr (e.g. RMarkdown) document # to include a list of objects in the Rmarkdown output # list of flextable objects library(flextable) listTables <- list(flextable(iris), flextable(cars)) knitPrintListObjects( xList = listTables, titles = c("Iris dataset", "Cars dataset") ) ## End(Not run)
Each plot is included (internally) in a separated chunk,
so different chunk options can be set for each plot.
For example, plots can be created with different
figure height or width (see examples).
knitPrintListPlots( plotsList, generalLabel = "plotsList", type = c("ggplot2", "plotly"), ... )
knitPrintListPlots( plotsList, generalLabel = "plotsList", type = c("ggplot2", "plotly"), ... )
plotsList |
list of plots, e.g. |
generalLabel |
general label for the chunks, used to build the |
type |
string with plot type: 'ggplot2' or 'plotly' |
... |
Arguments passed on to
|
This function should be called within a chunk
with the following option: results = 'asis'
.
Note that a (one-level) list of plotly
plots can
also be included directly via
htmltools::tagList(listPlots)
, but without the possibility to
have different chunk option for each plot.
No returned value, a text is printed with chunk content
Laure Cougnaud
## Not run: # Note: the following code should be included # within a chunk of a knitr (e.g. RMarkdown) document # to include a list of figures in the Rmarkdown output data(iris) ## Static plots library(ggplot2) plotsListStatic <- list( point = ggplot(data = cars, aes(x = speed, y = dist)) + geom_point(), line = ggplot(data = cars, aes(x = speed, y = dist)) + geom_line() ) # with general label (used to name exported figure) knitPrintListPlots( plotsList = plotsListStatic, generalLabel = "scatter-cars" ) # with label for each plot (used to name exported figure) knitPrintListPlots( plotsList = plotsListStatic, labels = names(plotsListStatic) ) # with section header (header of level 1 in Markdown) knitPrintListPlots( plotsList = plotsListStatic, titles = names(plotsListStatic), titleLevel = 3 ) # with caption for each figure knitPrintListPlots( plotsList = plotsListStatic, fig.cap = names(plotsListStatic) ) # specify dimension for each figure knitPrintListPlots( plotsList = plotsListStatic, # first plot has width of 3, second of 6 fig.width = c(3, 6), # both plots have a height of 6 fig.height = 6 ) ## Interactive plots library(plotly) plotsListInteractive <- list( point = plot_ly(data = cars, x = ~speed, y = ~dist, type = "scatter", mode = "marker"), line = plot_ly(data = cars, x = ~speed, y = ~dist, type = "scatter", mode = "line") ) # with titles knitPrintListPlots( plotsList = plotsListInteractive, type = "plotly", titles = names(plotsListInteractive), titleLevel = 3 ) ## End(Not run)
## Not run: # Note: the following code should be included # within a chunk of a knitr (e.g. RMarkdown) document # to include a list of figures in the Rmarkdown output data(iris) ## Static plots library(ggplot2) plotsListStatic <- list( point = ggplot(data = cars, aes(x = speed, y = dist)) + geom_point(), line = ggplot(data = cars, aes(x = speed, y = dist)) + geom_line() ) # with general label (used to name exported figure) knitPrintListPlots( plotsList = plotsListStatic, generalLabel = "scatter-cars" ) # with label for each plot (used to name exported figure) knitPrintListPlots( plotsList = plotsListStatic, labels = names(plotsListStatic) ) # with section header (header of level 1 in Markdown) knitPrintListPlots( plotsList = plotsListStatic, titles = names(plotsListStatic), titleLevel = 3 ) # with caption for each figure knitPrintListPlots( plotsList = plotsListStatic, fig.cap = names(plotsListStatic) ) # specify dimension for each figure knitPrintListPlots( plotsList = plotsListStatic, # first plot has width of 3, second of 6 fig.width = c(3, 6), # both plots have a height of 6 fig.height = 6 ) ## Interactive plots library(plotly) plotsListInteractive <- list( point = plot_ly(data = cars, x = ~speed, y = ~dist, type = "scatter", mode = "marker"), line = plot_ly(data = cars, x = ~speed, y = ~dist, type = "scatter", mode = "line") ) # with titles knitPrintListPlots( plotsList = plotsListInteractive, type = "plotly", titles = names(plotsListInteractive), titleLevel = 3 ) ## End(Not run)
Load data set in SAS format ('sas7bdat' or 'xpt') into R data.frames, from
files
or raw vector data
.
loadDataADaMSDTM( files, data, convertToDate = FALSE, dateVars = "DTC$", verbose = TRUE, encoding = "UTF-8", ... )
loadDataADaMSDTM( files, data, convertToDate = FALSE, dateVars = "DTC$", verbose = TRUE, encoding = "UTF-8", ... )
files |
Character vector with path to ADaM or SDTM file(s). |
data |
Named list with raw vector data
(as supported by: read_sas and read_xpt). |
convertToDate |
logical, if TRUE columns with date/time are converted to
|
dateVars |
vector of columns in |
verbose |
logical, if TRUE (by default) progress messages are printed during execution. |
encoding |
String with encoding, only used if |
... |
Additional parameters for the |
While creating the R data.frames, if date/time variables are present,
those are converted into to R date/time class
(see convertToDateTime
) function.
The labels of the ADaM/SDTM data sets are attached as attributes of the R data.frame.
List of data.frame with data of each ADAM file (if not empty), with special attributes:
'labelVars': named vector with label of the variables
'label': named vector with label of the datasets
Each data.frame contains an additional column called 'dataset'
specifying the name of the files
it was read from.
Laure Cougnaud
## Not run: dataFromSAS7bdat <- loadDataADaMSDTM(files = "ae.sas7bdat") attr(dataFromSAS7bdat, "labelVars") # column labels dataFromXpt <- loadDataADaMSDTM(files = c("ae.xpt", "dm.xpt")) attr(dataFromXpt, "labelVars") # column labels ## End(Not run)
## Not run: dataFromSAS7bdat <- loadDataADaMSDTM(files = "ae.sas7bdat") attr(dataFromSAS7bdat, "labelVars") # column labels dataFromXpt <- loadDataADaMSDTM(files = c("ae.xpt", "dm.xpt")) attr(dataFromXpt, "labelVars") # column labels ## End(Not run)
compareDiff
with the original newData
or oldData
.The newData
/oldData
are merged
with diffData
based on the columns of diffData
excepted 'Comparison type' and 'Version'.
mergeDiffWithData(diffData, newData, oldData)
mergeDiffWithData(diffData, newData, oldData)
diffData |
Object of class 'diff.data' containing
differences between datasets, as returned by the |
newData |
data.frame object representing the new data |
oldData |
data.frame object representing the old data |
The newData
or oldData
(as a data frame object)
with the extra column 'Comparison type' specifying the type
of change, either:
'Change': record present in both dataset based on the reference variables, but with changes in the changeable variables
'Addition': records present in new but not in old data
'Removal': records present in old but not in new data
'Identical': records identical in the old and new datasets (on both the reference and changeable variables)
Custom merge (left join) of difference data with some input data
mergeInputDiff(diffData, inputData, typeData, colsBy)
mergeInputDiff(diffData, inputData, typeData, colsBy)
diffData |
A |
inputData |
A |
typeData |
String with type of data, as "new" for |
colsBy |
Character vector of columns for doing the merge by. |
A data.table
object.
The inputData
is joined with the columns Comparison type
and Version
from the diffData
argument.
Function for reordering columns
reorderColumns(data, vars)
reorderColumns(data, vars)
data |
A |
vars |
Named vector indicating the position in the data frame of the specified variable |
The same data.frame
specified in data
,
with ordered columns.
someData <- data.frame( "Col1" = c(1, 2), "Col2" = c(2, 3), "Col3" = c(3, 4) ) reorderColumns( data = someData, vars = c("Col3" = 1) )
someData <- data.frame( "Col1" = c(1, 2), "Col2" = c(2, 3), "Col3" = c(3, 4) ) reorderColumns( data = someData, vars = c("Col3" = 1) )
This function rounds a number for a specified number of digits.
It rounds off to the highest number for a 5.
The default R round
function rounds to the
'even digit' in case of rounding off a 5
(see 'Details' section in ? round
).
This function instead rounds up to the nearest number for a 5.
It mimics a similar rounding strategy used in SAS.
See examples for the difference between round
and
'roundHalfUp' below.
roundHalfUp(x, digits = 0)
roundHalfUp(x, digits = 0)
x |
Numeric vector to round. |
digits |
Integer with number of digits to consider, 0 by default. |
Rounded numeric vector.
stackoverflow question 6461209
# numbers are rounded to the closest even number in case of .5 # with the round 'base' function round(0.45, 1) # 'roundHalfUp' always round to the next highest number in case of .5 roundHalfUp(0.45, 1) # rounding is the same for uneven number: round(0.55, 1) roundHalfUp(0.55) # other examples round(1.456e-2, digits = 3) round(1.456e-2, digits = 2) round(1.456e-2, digits = 1)
# numbers are rounded to the closest even number in case of .5 # with the round 'base' function round(0.45, 1) # 'roundHalfUp' always round to the next highest number in case of .5 roundHalfUp(0.45, 1) # rounding is the same for uneven number: round(0.55, 1) roundHalfUp(0.55) # other examples round(1.456e-2, digits = 3) round(1.456e-2, digits = 2) round(1.456e-2, digits = 1)
This function rounds numbers with a 'round-up' strategy for rounding off a 5. The function rounds for a specified number of digits and format number to a: 'xxx.xxx' text.
roundHalfUpTextFormat(x, digits = 0)
roundHalfUpTextFormat(x, digits = 0)
x |
Numeric vector to round. |
digits |
Integer with number of digits to consider, 0 by default. |
The following workflow is used:
numbers are rounded with the roundHalfUp
function, see the ? roundHalfUp
for more details
on the rounding strategy
round numbers are formatted to character in the format: 'xxx.xxx' with pads leading zeros
A character vector with the rounded number. NA values are returned as 'NA' as string.
Laure Cougnaud and Michela Pasetto
roundHalfUp for the rounding customization.
# number of digits higher than number of decimal roundHalfUpTextFormat(x = c(0.345, 0.567, -0.98), digits = 2) # number of digits lower than number of decimal roundHalfUpTextFormat(x = c(0.345, 0.567, -0.98), digits = 0) # by default, 'digits' is 0! roundHalfUpTextFormat(x = c(0.345, 0.567, -0.98)) # padding zeros roundHalfUpTextFormat(1.23, 10)
# number of digits higher than number of decimal roundHalfUpTextFormat(x = c(0.345, 0.567, -0.98), digits = 2) # number of digits lower than number of decimal roundHalfUpTextFormat(x = c(0.345, 0.567, -0.98), digits = 0) # by default, 'digits' is 0! roundHalfUpTextFormat(x = c(0.345, 0.567, -0.98)) # padding zeros roundHalfUpTextFormat(1.23, 10)
These symbols should be supported in Windows and Linux.
shapePaletteNRIND
shapePaletteNRIND
A named character vector with shape symbol for typical Normal Reference Range Indicator variable:
"LOW": filled down-pointing arrow (25
)
"NORMAL": filled circle (21)
"HIGH": filled up-pointing arrow (24
)
"ABNORMAL": diamond (18
)
"UNKNOWN" or 'NA': cross (3
)
"NA": cross (3
)
This implementation is inspired from the help of the toupper
function.
simpleCap(x, onlyFirst = TRUE, rev = FALSE)
simpleCap(x, onlyFirst = TRUE, rev = FALSE)
x |
Character vector to capitalize |
onlyFirst |
Logical, if TRUE (by default)
capitalize the first letter of the first word only.
Otherwise, capitalize the first letters of all words of the sentence.
See also |
rev |
Logical, if TRUE (FALSE by default), set first letter to lower case (otherwise upper case) |
Character vector with first letter capitalized
author of the 'toupper' function?
link[tools]{toTitleCase}
# capitalize only the first word of the sentence simpleCap(x = "this is the caption of my figure.") # capitalize all words simpleCap(x = "this is the caption of my figure.", onlyFirst = FALSE) # opposite: set the first letter of the first word to lower case simpleCap(x = "This is the caption of my figure.", rev = TRUE)
# capitalize only the first word of the sentence simpleCap(x = "this is the caption of my figure.") # capitalize all words simpleCap(x = "this is the caption of my figure.", onlyFirst = FALSE) # opposite: set the first letter of the first word to lower case simpleCap(x = "This is the caption of my figure.", rev = TRUE)