menu: Interactive CLI Menu

View source: R/menu.R

menuR Documentation

Description

Creates an interactive menu in the R console allowing users to select items. Inspired by inquirer.js, Python's pick, and Go's survey libraries.

Usage

menu(
  choices,
  prompt = "Select an item:",
  type = c("select", "checkbox"),
  selected = NULL,
  return_index = FALSE
)

Arguments

choices

Character vector of choices to display

prompt

Prompt message to display (default: "Select an item:")

type

Menu type: "select" (single) or "checkbox" (multiple) (default: "select")

selected

Pre-selected items (indices or values)

return_index

Return indices instead of values (default: FALSE)

Value

Selected item(s) as character vector or indices, or NULL if cancelled

Examples

if (interactive()) {
  # Single selection
  color <- menu(c("Red", "Green", "Blue"), prompt = "Pick a color:")

  # Multiple selection
  toppings <- menu(
    c("Pepperoni", "Mushrooms", "Olives"),
    type = "checkbox",
    prompt = "Select toppings:"
  )
}

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