Description Usage Arguments Value Note See Also
Normally, when using readline, execution is halted until input is supplied, and if it is not, the script hangs forever This functions waits a set time for the user to provide input, then returns control
1 | readline_time(prompt, timeout = 3600, precision = 0.1)
|
prompt |
prompt for the user, similar to the one in readline(). Usually ends with a space (or newline). |
timeout |
timer in seconds. If set to 0, base::readline is used |
precision |
Polling interval in seconds. |
Input provided by the user, if provided in time (and finished with RETURN)
If the timer has expired, character(0)
, even if the user has started typing but has not yet pressed RETURN.
If used in a non-interactive session, NULL, and if the timer has expired, character(0).
If timeout==0, the same as provided by readline()
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 timeout first.
waitForKey
for a function that simply waits for a keypress for a set time.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.