
readline
reads a line from the terminal (in interactive use).readline(prompt = "")
" "
.""
.readLines
for reading text lines from connections,
including files.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()
Run the code above in your browser using DataLab