waitForKey: Wait for set time, or continue on input.

Description Usage Arguments Value Note See Also

View source: R/Misc.R

Description

Waits until a timer has expired, or the user has provided some input (pressed RETURN)
A message is shown, with a countdown-timer if desired.

Usage

1
2
waitForKey(message = "Continuing in {n} seconds, or press any key.",
  time = 10, counter = 0.5, precision = 0.01)

Arguments

message

Message to be shown during countdown. Use n as a placeholder for the number of seconds left.

time

Time to wait, in seconds (approximate)

counter

Interval to update the message, in seconds. 0 to remain static. Must otherwise be a multiple of precision to work reliably.

precision

Polling interval to use when checking for a keypress.

Value

(invisibly) Either the string 'key' or 'timer', signifying what caused the return

Note

Unfortunately, does not work on all platforms/in all environments.
It is dependent on being able to read from file('stdin'), which is different from stdin(), see file for details. In particular, it does not work in RStudio for MacOS, or Rgui for Windows or MacOS. It does confirmed work on R run from terminal on MacOS 10.13.6
Problems manifest by file('stdin') not being connected to anything, i.e. no input is received, so this function always returns character(0), and any input typed is interpreted as a new command. To test, try with a small value of time first.

See Also

readline_time for a function that also collects your input.


EmilBode/EmilMisc documentation built on Feb. 24, 2020, 4:11 p.m.