R/interact-program.R

Defines functions cmd_input

Documented in cmd_input

#' Read multiple lines of input from prompt
#'
#' A simple function to read line by line from R
#' console input. Note that \emph{leading and
#' trailing white spaces are trimed}.
#'
#' @return Returns a character vector with length
#'   equal to the total number of input lines.
#'   Each element of the vector corresponds to 1
#'   line of input value.
#'
#' @examples
#' \dontrun{
#' input <- read_cmd()
#' }
#' @keywords internal
cmd_input <- function() {
  msg <- NULL
  num <- 1
  cat('When finished, key in "EOF" to exit.')
  Sys.sleep(0.7)
  while (TRUE) {
    temp <- readline(paste0('line ', num, ': '))
    if (temp == 'EOF') break
    num <- num + 1
    msg <- c(msg, temp)
  }
  return(msg)
}
deeplexR/lexicoR documentation built on May 26, 2019, 2:33 a.m.