dlg_input: Modal dialog to input a string or a value.

View source: R/dlg_input.R

dlg_inputR Documentation

Modal dialog to input a string or a value.

Description

Prompt for some data in a modal dialog box.

Usage

dlg_input(message = "Enter a value", default = "", ..., gui = .GUI)

dlgInput(message = "Enter a value", default = "", ..., gui = .GUI)

## S3 method for class 'gui'
dlg_input(message = "Enter a value", default = "", ..., gui = .GUI)

## S3 method for class 'textCLI'
dlg_input(message = "Enter a value", default = "", ..., gui = .GUI)

## S3 method for class 'nativeGUI'
dlg_input(
  message = "Enter a value",
  default = "",
  rstudio = getOption("svDialogs.rstudio", TRUE),
  ...,
  gui = .GUI
)

Arguments

message

The message to display in the dialog box. Use \\n for line break, or provide a vector of character strings, one for each line.

default

The default value in the text box. Single string or NULL.

...

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. The text entered by the user at the input box, or an empty string if the dialog box was cancelled can be obtained from gui$res (see example).

Note

The 'RStudio' version of this dialog box does not allow for an empty string. So, for better portability, try never to expect an empty string from the user (the 'Cancel' button is there to dismiss the dialog box). On MacOS, single and double quotes are temporarily replaced by their slanted versions (unicode characters u3032 and u2033, respectively) because the command that triggers the dialog box does not allow quotes inside strings. Regular quotes are reset on the output. This is the only hack we found that was working. Better solutions are welcome!

See Also

dlg_list(), dlg_form(), dlg_message()

Examples

## Not run: 
# Ask something...
user <- dlg_input("Who are you?", Sys.info()["user"])$res
if (!length(user)) {# The user clicked the 'cancel' button
  cat("OK, you prefer to stay anonymous!\n")
} else {
  cat("Hello", user, "\n")
}

## End(Not run)

svDialogs documentation built on May 10, 2022, 9:06 a.m.