pretty_DT.RdCreate pretty datatable with custom bolding options.
pretty_DT(
X,
digits = 3,
sigfig = T,
escape = F,
rownames = TRUE,
caption = "",
na_disp = "NA",
bold_function = NULL,
bold_margin = NULL,
bold_scheme = T,
bold_color = NULL,
grouped_header = NULL,
grouped_subheader = NULL,
options = list(),
return_df = FALSE,
...
)Data frame or data matrix to display in table
Number of digits to display for numeric values
Logical. If TRUE, digits refers to the number of
significant figures. If FALSE, digits refers to the number of
decimal places.
Logical. Whether or not to escape HTML entities in table. See
DT::datatable() for details.
Logical. Whether or not to show rownames in table. See
DT::datatable() for details.
The table caption.
Character string to display if NA entry is found in table.
Optional function or vector of functions
to use for bolding entries, e.g. function(x) x == max(x) or
function(x) x >= 0.5.
Specifies the margins of X that will be used to evaluate
bold_function across, i.e., 0 = across entire matrix, 1 = across
rows, and 2 = across columns. Required if bold_function = TRUE.
Scalar or vector of logicals, indicating whether or not
to apply bold_function to row if bold_margin = 1 and to
column if bold_margin = 1, 2. Default is to apply bolding to all
rows/columns.
Color of bolded text.
A (named) character vector with colspan as values.
For example, c(" " = 1, "title" = 2) can be used to create a new header
row for a 3-column table with "title" spanning across column 2 and 3. Used
to group columns.
A character vector with the names of the columns below the grouped header row.
See options argument in DT::datatable().
Logical. If TRUE, return data frame that was used
as input into DT::datatable() in addition to the datatable output.
If FALSE, only return the datatable output.
Additional arguments to pass to DT::datatable().
If return_df = FALSE, returns a datatable object. Otherwise,
returns a list of two:
A datatable object.
A data frame that was used as input into DT::datatable().
# Show iris data table
pretty_DT(iris, caption = "Iris Data Table")
# Bold max value of each numeric column of Iris data in red
pretty_DT(iris, caption = "Iris Data Table",
bold_function = function(x) x == max(x), bold_margin = 2,
bold_scheme = c(TRUE, TRUE, TRUE, TRUE, FALSE), bold_color = "red")
# Bold min value of each row in Iris data
pretty_DT(iris %>% dplyr::select(-Species),
sigfig = TRUE, caption = "Iris Data Table",
na_disp = "NA", bold_function = function(x) x == min(x),
bold_margin = 1, bold_scheme = TRUE, bold_color = "black")
# Add grouped column header
pretty_DT(iris[, c(5, 1:4)],
rownames = FALSE,
grouped_header = c(" " = 1, "Sepal" = 2, "Petal" = 2))
pretty_DT(iris[, c(5, 1:4)],
rownames = FALSE,
grouped_header = c(" " = 1, "Sepal" = 2, "Petal" = 2),
grouped_subheader = c("Species", "Length", "Width", "Length", "Width"))
pretty_DT(iris[, c(5, 1:4)],
rownames = FALSE,
grouped_header = c(" " = 1, "Sepal" = 2, " " = 2),
grouped_subheader = c("Species", "Length", "Width", "Petal.Length", "Petal.Width"))