Learn R Programming

blockr.dplyr (version 0.1.0)

new_summarize_block: Summarize block constructor

Description

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(),
  ...
)

Value

A block object for no-code summarize operations

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()

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.

Details

For expression-based summarization, see new_summarize_expr_block().

See Also

blockr.core::new_transform_block(), new_summarize_expr_block()

Examples

Run this code
# Create a summarize block
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)
  )
}

Run the code above in your browser using DataLab