Skip to contents

This block provides a no-code interface for summarizing data (see dplyr::summarize()). Instead of writing expressions, users select summary functions from dropdowns (mean, median, sum, etc.), choose columns to summarize, and specify new column names.

Usage

new_summarize_block(
  summaries = list(count = list(func = "dplyr::n", col = "")),
  by = character(),
  ...
)

Arguments

summaries

Named list where each element is a list with 'func' and 'col' elements. For example: list(avg_mpg = list(func = "mean", col = "mpg"))

by

Columns to define grouping

...

Additional arguments forwarded to blockr.core::new_block()

Value

A block object for no-code summarize operations

Details

For expression-based summarization, see new_summarize_expr_block().

Extending available functions

The list of available summary functions can be extended using the blockr.dplyr.summary_functions option. Set this option to a named character vector where names are display labels and values are function calls:


options(
  blockr.dplyr.summary_functions = c(
    "extract parentheses (paren_num)" = "blockr.topline::paren_num"
  )
)

If a description is not provided (empty name), the function name will be used as the display label.

Examples

# Create a summarize block
new_summarize_block()
#> <summarize_block<transform_block<block>>>
#> Name: "Summarize"
#> Data inputs: "data"
#> Initial block state:
#>  $ summaries:List of 1
#>   ..$ count:List of 2
#>   .. ..$ func: chr "dplyr::n"
#>   .. ..$ col : chr ""
#>  $ by       : chr(0)
#> Constructor: blockr.dplyr::new_summarize_block()

if (interactive()) {
  # Basic usage with mtcars dataset
  library(blockr.core)
  serve(new_summarize_block(), data = list(data = mtcars))

  # With predefined summaries
  serve(
    new_summarize_block(
      summaries = list(
        avg_mpg = list(func = "mean", col = "mpg"),
        max_hp = list(func = "max", col = "hp")
      )
    ),
    data = list(data = mtcars)
  )

  # With grouping
  serve(
    new_summarize_block(
      summaries = list(avg_mpg = list(func = "mean", col = "mpg")),
      by = "cyl"
    ),
    data = list(data = mtcars)
  )
}