Learn R Programming

svDialogs (version 1.1.0)

dlg_list: Modal dialog to select one or more items in a list.

Description

Display a list and allow user to select either one, or multiple items in that list.

Usage

dlg_list(
  choices,
  preselect = NULL,
  multiple = FALSE,
  title = NULL,
  ...,
  gui = .GUI
)

dlgList( choices, preselect = NULL, multiple = FALSE, title = NULL, ..., gui = .GUI )

# S3 method for gui dlg_list( choices, preselect = NULL, multiple = FALSE, title = NULL, ..., gui = .GUI )

# S3 method for textCLI dlg_list( choices, preselect = NULL, multiple = FALSE, title = NULL, ..., gui = .GUI )

# S3 method for nativeGUI dlg_list( choices, preselect = NULL, multiple = FALSE, title = NULL, rstudio = getOption("svDialogs.rstudio", TRUE), ..., gui = .GUI )

Arguments

choices

The list of items. It is coerced to character strings.

preselect

A list of preselections, or NULL (then, the first element is selected in the list). Preselections not in choices are tolerated (but they are ignored without warning or error).

multiple

Is it a multiple selection dialog box?

title

The title of the dialog box, or NULL to use a default title instead.

...

Pass further arguments to methods.

gui

The 'gui' object concerned by this dialog box.

rstudio

Logical. Should 'RStudio' dialog boxes automatically be used if available? If FALSE, force using OS dialog boxes, but only in 'RStudio Desktop' (ignored in 'RStudio Server'). Can be changed globally with options(svDialogs.rstudio = TRUE|FALSE). TRUE by default.

Value

The modified 'gui' object is returned invisibly. A list with selected items, or a character vector of length 0 if the dialog box was cancelled is available from gui$res (see examples).

See Also

dlg_form(), dlg_input()

Examples

Run this code
# NOT RUN {
# Select one or several months
res <- dlg_list(month.name, multiple = TRUE)$res
if (!length(res)) {
  cat("You cancelled the choice\n")
} else {
  cat("You selected:\n")
  print(res)
}
# }

Run the code above in your browser using DataLab