readline

0th

Percentile

Read a Line from the Terminal

readline reads a line from the terminal (in interactive use).

Keywords
utilities
Usage
readline(prompt = "")
Arguments
prompt
the string printed when prompting the user for input. Should usually end with a space " ".
Details

The prompt string will be truncated to a maximum allowed length, normally 256 chars (but can be changed in the source code).

This can only be used in an interactive session.

Value

A character vector of length one. Both leading and trailing spaces and tabs are stripped from the result.In non-interactive use the result is as if the response was RETURN and the value is "".

See Also

readLines for reading text lines from connections, including files.

Aliases
  • readline
Examples
library(base) fun <- function() { ANSWER <- readline("Are you a satisfied R user? ") ## a better version would check the answer less cursorily, and ## perhaps re-prompt if (substr(ANSWER, 1, 1) == "n") cat("This is impossible. YOU LIED!\n") else cat("I knew it.\n") } if(interactive()) fun()
Documentation reproduced from package base, version 3.1.3, License: Part of R 3.1.3

Community examples

Looks like there are no examples yet.