Learn R Programming

climenu (version 0.1.4)

checkbox: Multiple Selection Menu (Checkbox)

Description

Interactive menu for selecting multiple items from a list. Uses arrow keys (or j/k) to navigate, Space to toggle, and Enter to confirm. Optionally includes a "Select all" / "Deselect all" option at the top when allow_select_all = TRUE.

Usage

checkbox(
  choices,
  prompt = "Select items (Space to toggle, Enter to confirm):",
  selected = NULL,
  return_index = FALSE,
  max_visible = 10L,
  allow_select_all = FALSE
)

Value

Selected items as character vector or indices, or NULL if cancelled. The special "Select all" option is never included in the returned results.

Arguments

choices

Character vector of choices to display

prompt

Prompt message to display

selected

Pre-selected items (indices or values)

return_index

Return indices instead of values (default: FALSE)

max_visible

Maximum number of items to display at once (default: 10). Set to NULL to show all items.

allow_select_all

If TRUE, adds a "Select all" / "Deselect all" option at the top of the menu. When selected, toggles all items at once. The option text dynamically changes based on selection state (default: FALSE).

Examples

Run this code
if (interactive()) {
  toppings <- checkbox(
    c("Pepperoni", "Mushrooms", "Olives"),
    prompt = "Select toppings:"
  )

  # With pre-selection
  options <- checkbox(
    c("Option A", "Option B", "Option C"),
    selected = c(1, 3)
  )

  # With scrolling for long lists
  items <- checkbox(1:100, max_visible = 10)

  # With select all feature
  methods <- checkbox(
    c("method_a", "method_b", "method_c"),
    allow_select_all = TRUE,
    prompt = "Select methods to run:"
  )
}

Run the code above in your browser using DataLab