Get or set style of a colorful data frame

df_style(x, element = NULL) <- value

df_style(x, element)

Arguments

x

a colorful data frame

element

element or elements of the style

value

one or more values to set

Value

df_style(x) returns a list. Assignment results in a data frame with a modified style.

Details

Colorful data frames store the styles in the .style attribute of the data frame object. This attribute is a list with a number of keywords:

  • fg, bg, decoration: formatting styles to be applied to the whole table (see "Formatting styles" below)

  • row.names, col.names, interleave: formatting styles for row names, table header and every second line in the table. If these elements are NULL, no styles will be applied. See "Formatting styles" below.

  • autoformat (logical): whether column type should be guessed from column names (which allows automatically recognizing a column called "pvalue" as a p-value and color significant cells.

  • col.styles: a list mapping the column names to formatting styles.

  • col.types: a list mapping the column names to column types. For example, if it is list(result="pval"), then the column with name "result" will be considered to be a p-value and styled accordingly.

  • type.styles: a list mapping column types to formatting styles. See "Formatting styles" below and help page for col_type().

  • fixed.width: if not NULL, all columns have the same width

  • sep: string separating the columns

  • digits: how many digits to use

  • tibble.style: if not NULL, cut off columns that do not fit the width

Formatting styles

Each formatting style is a list describing style of the formatting and coloring the text elements. Following elements of that list are recognized:

  • fg, bg: foreground and background colors specified as R name (use colors() to get available colors) or HTML hexadicimal code

  • fg_sign: for p-values, foreground color for significant values

  • fg_true, fg_false: foreground colors for logical vectors

  • fg_neg: for numeric values, foreground color for negative values

  • fg_na: color for NA values

  • is.pval: whether the values are to be treated as p-values

  • is.numeric: whether the values are to be treated as numeric

  • align: how the values should be aligned (right, left or center)

  • sign.thr: for p-values, the threshold of significance

  • digits: how many digits to use

  • decoration: a character vector which may include the following key words: inverse, bold, italic

See also

print.colorDF() on printing options; col_type() for column types.

Examples

df <- as.colorDF(mtcars)

## row names should be red on yellow background (yikes!)
df_style(df, "row.names") <- list(fg="red", bg="#FFFF00")

## you can use `$` to access the elements
## here, show significant p-values in green
df_style(df)$type.styles$pval$fg_sign <- "green"

## example of assigning multiple values in one assignment:
df_style(df) <- list(interleave=list(fg="#FFFFFF", bg="blue"),
                  row.names=list(fg="blue", bg="#FFFF00"), 
                  col.names=list(bg="#FFFFFF", fg="#FF00FF", 
                                 decoration=c("bold", "italic")))