select: Single Selection Menu

View source: R/select.R

selectR Documentation

Single Selection Menu

Description

Interactive menu for selecting a single item from a list. Uses arrow keys (or j/k) to navigate and Enter to select.

Usage

select(
  choices,
  prompt = "Select an item:",
  selected = NULL,
  return_index = FALSE,
  max_visible = 10L
)

Arguments

choices

Character vector of choices to display

prompt

Prompt message to display

selected

Pre-selected item (index or value)

return_index

Return index instead of value (default: FALSE)

max_visible

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

Value

Selected item as character or index, or NULL if cancelled

Examples

if (interactive()) {
  choice <- select(c("Yes", "No", "Maybe"))
  index <- select(c("First", "Second", "Third"), return_index = TRUE)

  # With scrolling for long lists
  choice <- select(1:100, max_visible = 10)
}

climenu documentation built on Feb. 6, 2026, 5:08 p.m.