R/question.R

Defines functions yesno

Documented in yesno

#' Yes or No
#'
#' Asks user a question and returns a TRUE or FALSE to indicate
#' whether user answered yes or no.
#' Modified from devtools package internal function so that yes returns TRUE.
#'
#' @param question a character scalar of the question to ask the user
#' @return A logical scalar indicating whether reponse was yes (TRUE) or no (FALSE).
#' @export
yesno <- function(question) {
  yeses <- c("Yes", "Yup", "Yeah")
  nos <- c("No", "No way", "Nope")

  cat(question)
  qs <- c(sample(yeses, 1), sample(nos, 2))
  rand <- sample(length(qs))

  utils::menu(qs[rand]) == which(rand == 1)
}
poissonconsulting/tulip documentation built on Feb. 18, 2021, 11:18 p.m.