utils (version 3.6.2)

askYesNo: Ask a Yes/No Question


askYesNo provides a standard way to ask the user a yes/no question. It provides a way for front-ends to substitute their own dialogs.


askYesNo(msg, default = TRUE, 
         prompts = getOption("askYesNo", gettext(c("Yes", "No", "Cancel"))), 



The prompt message for the user.


The default response.


Any of: a character vector containing 3 prompts corresponding to return values of TRUE, FALSE, or NA, or a single character value containing the prompts separated by / characters, or a function to call.

Additional parameters, ignored by the default function.


TRUE for yes, FALSE for no, and NA for cancel.


askYesNo will accept case-independent partial matches to the prompts. If no response is given the value of default will be returned; if a non-empty string that doesn't match any of the prompts is entered, an error will be raised.

If a function or single character string naming a function is given for prompts, it will be called as fn(msg = msg, default = default, prompts = prompts, ...). On Windows, the GUI uses the unexported utils:::askYesNoWinDialog function for this purpose.

If strings (or a string such as "Y/N/C") are given as prompts, the choices will be mapped to lowercase for the non-default choices, and left as-is for the default choice.

See Also

readline for more general user input.


Run this code
if (interactive())
    askYesNo("Do you want to use askYesNo?")
# }

Run the code above in your browser using DataLab