Learn R Programming

blockr.dplyr (version 0.1.0)

new_slice_block: Slice block constructor

Description

This block allows row selection using various dplyr slice functions (see dplyr::slice(), dplyr::slice_head(), dplyr::slice_tail(), dplyr::slice_min(), dplyr::slice_max(), dplyr::slice_sample()). Features reactive UI with immediate updates and comprehensive grouping support.

Usage

new_slice_block(
  type = "head",
  n = 5,
  prop = NULL,
  order_by = character(),
  with_ties = TRUE,
  weight_by = character(),
  replace = FALSE,
  rows = "1:5",
  by = character(),
  ...
)

Value

A block object for slice operations

Arguments

type

Character string specifying slice type: "head", "tail", "min", "max", "sample", or "custom"

n

Number of rows to select (default: 5). Mutually exclusive with prop.

prop

Proportion of rows to select (0 to 1, default: NULL). When specified, n is ignored.

order_by

Column name to order by (for slice_min/slice_max)

with_ties

Logical, whether to include ties (for slice_min/slice_max)

weight_by

Column name for weighted sampling (for slice_sample)

replace

Logical, whether to sample with replacement (for slice_sample)

rows

Custom row positions (for slice)

by

Character vector of column names for grouping

...

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

See Also

blockr.core::new_transform_block()

Examples

Run this code
# Create a slice block
new_slice_block(type = "head", n = 5)

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

  # Select first 5 rows
  serve(new_slice_block(type = "head", n = 5), list(data = mtcars))

  # Select rows with highest mpg values
  serve(new_slice_block(type = "max", order_by = "mpg", n = 3), list(data = mtcars))

  # Random sampling
  serve(new_slice_block(type = "sample", n = 10, replace = FALSE), list(data = mtcars))
}

Run the code above in your browser using DataLab