View source: R/table-getClinDT.R
getClinDT | R Documentation |
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, ... )
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.