Learn R Programming

exams.forge (version 1.0.11)

select_menu: 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")
)

Value

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

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.

See Also

Examples

Run this code
if (FALSE) {
# Example usage:
options <- c("Apple", "Banana", "Cherry", "Date")
selected <- select_menu(options, title = "Choose your fruits:")
cat("You selected:", paste(selected, collapse = ", "), "\n")
}

Run the code above in your browser using DataLab