Skip to content
Prev 38587 / 63424 Next

Wait for user input with readline()

Hi,

I have a similar problem as the one of Nate. The point is that I want to
design an interactive script that need the value of two variables (x and y).

So my script as designed for the moment is :

x <- as.numeric (readline(prompt="What is the value of x? "))
y <- as.numeric (readline(prompt="What is the value of y? "))

x
y 

But the problem is that if I run this script, values returned for x and y
will be "NA" like you can see below :
What is the value of x?
What is the value of y?
[1] NA
[1] NA

I have no problem to understand why, because R software does not let the
time to enter the value for each variable. So Nate and I want to know if
there is a way, to "force" R to wait the entrance of the value of each
variable like written below:

First step of the script :
What is the value of x? 5

Second step of the script :
What is the value of y? 9

Finally :
[1] 5
[1] 9

I hope that my english is not to bad and that you've understand what I mean.

Regards

Alexandre