A More Sane yesno() for devtools

There’s an updated approach in this new post.

When working with devtools, you’ll often be asked a yes/no question and get the annoying prompt of three randomly ordered and randomly worded variations of "Yes" and "No", so that you have to think hard to pick the right one. I get what they’re trying to do (force you to actually think about the question rather than hitting "Y" repeatedly) but I find it very annoying. Here’s a fix.

Add this code to your .Rprofile, and you’ll now get a static 1: Yes, 2: No prompt.

suppressMessages(require(devtools))
yesno <- function(...) {
  cat(paste0(..., collapse = ""))
  # For whatever reason, devtools:::yesno returns `TRUE` if you
  # select a No option, and `FALSE` if you select a Yes option
  utils::menu(c("Yes", "No")) != 1
}
utils::assignInNamespace("yesno", yesno, "devtools")
# remove stand-alone `yesno`
rm(yesno)
Home | Back to blog

This work is licensed under CC BY-NC 4.0 Creative Commons BY-NC image