Skip to content
Prev 38602 / 63424 Next

Wait for user input with readline()

Part of the problem seems to be that R is set up to run in 1 of 2 modes (I may be over generalizing or over simplifying here), the modes are interactive where you type in a command, R processes it and gives results, you type in another command, etc.  The other is Batch mode where everything is processed without user interaction.

You (and others) seem to want some combination of the 2, but it is not clear exactly how to merge the 2 modes for general.  You are asking the computer to try to read your mind about when to use the next line of the script as input and when to wait for the user.

Some possibilities for you being able to tell the computer what to do:

Convert your script to a function with the readlines inside the function, then run the function from the prompt (then the readlines will expect user input).

Use tcltk (or other GUI tools) to have a separate box pop-up to get the input (this will not allow the entry to ever be automated, the script will wait until the entry is submitted).

You could combine these using if statements on the results of the interactive() function to help decide whether to pop up the boxes or not.

Hope this helps,