How to wait for a keypress in R?

Contango picture Contango · Mar 7, 2013 · Viewed 90.7k times · Source

I want to pause my R script until the user presses a key.

How do I do this?

Answer

nnn picture nnn · Sep 11, 2013

As someone already wrote in a comment, you don't have to use the cat before readline(). Simply write:

readline(prompt="Press [enter] to continue")

If you don't want to assign it to a variable and don't want a return printed in the console, wrap the readline() in an invisible():

invisible(readline(prompt="Press [enter] to continue"))