Generate column definitions for aggregating specified columns by a specified metric in a Reactable table
colDef_agg.Rd
The colDef_agg
function generates column definitions for aggregating specified columns
by a specified metric in a Reactable table. It creates column definitions based on provided column
names, a metric aggregation function, and whether to remove the footer from the column definitions.
Arguments
- cols
A character vector specifying the column names to be aggregated.
- rm_footer
A logical value indicating whether to remove the footer from the column definitions. Default is
TRUE
.- agg_fun
A character string specifying the aggregation function to be applied. Default is
"sum"
. Other possible values include functions available in thedplyr
package such as"mean"
,"median"
, etc.
Value
A list of column definitions suitable for use in a Reactable table with specified columns aggregated by the specified metric.
Examples
library(dplyr)
#>
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#>
#> filter, lag
#> The following objects are masked from ‘package:base’:
#>
#> intersect, setdiff, setequal, union
library(tibble)
library(magrittr)
library(reactable)
mtcars %>%
rownames_to_column("cars") %>%
mutate(cars = gsub(" .*", "\\1", cars)) %>%
reactable(
defaultColDef = colDef(footerStyle = list(fontWeight = "bold")),
groupBy = "cars",
columns = combined_named_lists(
colDef_agg(cols = c("am", "gear", "carb"), agg_fun = "sum")
)
)
#> Error in map(., ~.x[names(.x) != "footer"]): could not find function "map"