Specify column definitions for instances of many columns at once without specifying them individually
rtrn_cols.Rd
The rtrn_cols
function simplifies the process of specifying column definitions for instances
of many columns at once without specifying them individually. It takes a singular string input as the
source of column names, where the "|" operator signifies "or". If exclude = TRUE
, it returns
all columns that are not specified in the input string.
Arguments
- data
The data frame from which column names are extracted.
- words
A singular string input containing column names, where "|" signifies "or".
- pretty
A logical value indicating whether to return the column names in a pretty format. Default is
FALSE
.- exclude
A logical value indicating whether to exclude the specified columns. Default is
FALSE
.- sort
A logical value indicating whether to sort the column names alphabetically. Default is
TRUE
.
Examples
# Create example data
temp_data <- mtcars %>%
rownames_to_column("cars") %>%
mutate(cars = gsub(" .*", "\\1", cars))
print(rtrn_cols(data = temp_data, words = "cars", exclude = T))
#> [1] "am" "carb" "cyl" "disp" "drat" "gear" "hp" "mpg" "qsec" "vs"
#> [11] "wt"
print(rtrn_cols(data = temp_data, words = "cars", exclude = F))
#> [1] "cars"
# Create a Reactable table with specified column definitions
temp_data %>%
reactable(
defaultColDef = colDef(footerStyle = list(fontWeight = "bold")),
groupBy = "cars",
columns = combined_named_lists(
colDef_agg(cols = rtrn_cols(data = temp_data, words = "cars", exclude = TRUE)),
colDef_hide(cols = rtrn_cols(data = temp_data, words = "gear|am", exclude = FALSE))
)
)
#> Error in map(., ~.x[names(.x) != "footer"]): could not find function "map"