How to Wait for a Keypress in R (Example Code)

In this tutorial, I’ll show how to pause an R script until a key is pressed in R programming.

Example: Using Keypress within Manually Specified Function in R

my_function <- function(input) {    # Constructing own function
  
  output <- input + 10
 
  readline(prompt = "Press [enter] to return the result of your input + 10.")
 
  output
}
my_function(input = 20)             # Applying own function to input value

“Press [enter] to return the result of your input + 10.”

# [1] 30

Leave a Reply

Your email address will not be published.

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top