Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

ask

Display a prompt and collect the user's response


Description

Display a prompt and collect the user's response

Usage

ask(msg = "Press <RETURN> to continue: ", con=stdin())

Arguments

msg

Character vector providing the message to be displayed

con

Character connection to query, defaults to stdin().

Details

The prompt message will be displayed, and then readLines is used to collect a single input value (possibly empty), which is then returned.

In most situations using the default con=stdin() should work properly. Under RStudio, it is necessary to specify con=file("stdin") for proper operation.

Value

A character scalar containing the input provided by the user.

Author(s)

Gregory R. Warnes greg@warnes.net

See Also

Examples

# use default prompt
ask()

silly <- function()
{
   age <- ask("How old aroe you? ")
   age <- as.numeric(age)
   cat("In 10 years you will be", age+10, "years old!\n")
}

gtools

Various R Programming Tools

v3.8.2
GPL-2
Authors
Gregory R. Warnes, Ben Bolker, and Thomas Lumley
Initial release
2020-03-23

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.