select_menu: Display a Menu for User Selection

View source: R/select_menu.R

select_menuR Documentation

Display a Menu for User Selection

Description

Presents a list of choices to the user, allowing them to select one or more options by entering numbers. If the user inputs an empty line, the function skips the selection and returns NULL.

Usage

select_menu(
  choices,
  title = NULL,
  msg = "Enter one or more numbers, or an empty line to open files: ",
  width = getOption("width")
)

Arguments

choices

character: vector of options to display to the user. Each choice will be prefixed with a numbered label.

title

character: optional string to display as the title of the menu. Default is NULL, meaning no title is displayed.

msg

character: string specifying the prompt message for user input. Default is "Enter one or more numbers, or an empty line to open files: ".

width

integer: specifying the maximum line width for displaying the menu. Defaults to the value of the width option (getOption("width")).

Details

This documentation was created with the support of ChatGPT.

Value

A character vector of selected choices, or NULL if the user enters an empty line.

See Also

Based on select_menu() in the package remotes

Examples

## Not run: 
# Example usage:
options <- c("Apple", "Banana", "Cherry", "Date")
selected <- select_menu(options, title = "Choose your fruits:")
cat("You selected:", paste(selected, collapse = ", "), "\n")

## End(Not run)


exams.forge documentation built on Aug. 21, 2025, 5:41 p.m.