Set or retrieve a column type of a colorful data frame
col_type(x, cols = NULL) <- value
col_type(x, cols = NULL)
a colorful data frame
column names to set or retrieve
character vector with column types
Rather than directly assigning a style to a column (which is possible
using the col.styles
element) it is preferable to change a style
associated with a column type. Several such types are defined in the
default styles:
character
numeric
integer
factor
identifier
pval
match
hidden
default
Of course, new column types may be defined and their formatting defined in a theme or a particular data frame style.
mc <- colorDF(mtcars)
col_type(mc, "gear") <- "factor"
col_type(mc, "gear")
#> [1] "factor"
col_type(mc) <- list(gear="factor", cyl="integer")
## Note: the *class* of the columns did not change!
## Chaning column type merely changes the way it is displayed
class(mc[["gear"]])
#> [1] "numeric"
## Hide some columns
col_type(mc, c("disp", "hp")) <- "hidden"
## Create a new type and style
col_type(mc, "carb") <- "carbstyle"
df_style(mc)$type.styles$carbstyle <- list(fg="red", decoration="bold")