loading...

Prompt for some data in a modal dialog box.

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

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

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

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

# S3 method for 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!

Examples

if (FALSE) {
# 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")
}
}