dlg_message {svDialogs} | R Documentation |
Display a modal message box.
Description
A message box with icon, text, and one to three buttons.
Usage
dlg_message(
message,
type = c("ok", "okcancel", "yesno", "yesnocancel"),
...,
gui = .GUI
)
dlgMessage(
message,
type = c("ok", "okcancel", "yesno", "yesnocancel"),
...,
gui = .GUI
)
msg_box(message)
msgBox(message)
ok_cancel_box(message)
okCancelBox(message)
## S3 method for class 'gui'
dlg_message(
message,
type = c("ok", "okcancel", "yesno", "yesnocancel"),
...,
gui = .GUI
)
## S3 method for class 'textCLI'
dlg_message(
message,
type = c("ok", "okcancel", "yesno", "yesnocancel"),
...,
gui = .GUI
)
## S3 method for class 'nativeGUI'
dlg_message(
message,
type = c("ok", "okcancel", "yesno", "yesnocancel"),
rstudio = getOption("svDialogs.rstudio", TRUE),
...,
gui = .GUI
)
Arguments
message |
The message to display in the dialog box. Use |
type |
The type of dialog box: |
... |
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 |
Value
The modified 'gui' object is returned invisibly. A string with the
name of the button ("ok"
, "cancel"
, "yes"
or "no"
) that the user
pressed can be obtained from gui$res
(see example).
msg_box()
just returns the name of the button ("ok"
), while
ok_cancel_box()
returns TRUE
if "ok" was clicked or FALSE
if "cancel"
was clicked.
Note
On 'RStudio' or with 'zenity' under Linux, only two buttons are
available. So, when using type = "yesnocancel"
, two successive dialog boxes
are displayed: one with the message and 'yes'
/'no'
buttons, and a second
one asking to continue, and if the user clicks 'no'
, the function returns
"cancel"
. This is clearly sub-optimal. So, for a clean experience on all
supported platforms, try to avoid 'yesnocancel'
as much as possible.
See Also
Examples
## Not run:
# A simple information box
dlg_message("Hello world!")$res
# Ask to continue
dlg_message(c("This is a long task!", "Continue?"), "okcancel")$res
# Ask a question
dlg_message("Do you like apples?", "yesno")$res
# Idem, but one can interrupt too
res <- dlg_message("Do you like oranges?", "yesnocancel")$res
if (res == "cancel")
cat("Ah, ah! You refuse to answer!\n")
# Simpler version with msgBox and okCancelBox
msg_box("Information message") # Use this to interrupt script and inform user
if (ok_cancel_box("Continue?")) cat("we continue\n") else cat("stop it!\n")
## End(Not run)