From savicky at cs.cas.cz  Tue Dec  7 18:19:21 2010
From: savicky at cs.cas.cz (Petr Savicky)
Date: Tue, 7 Dec 2010 18:19:21 +0100
Subject: [Rd] Wait for user input with readline()
In-Reply-To: <1291652739318-3074781.post@n4.nabble.com>
References: <AANLkTikAG_8ynt2+SP=b5WYJ2u2w5iwqit=0R_1FDsJr@mail.gmail.com>
	<1291652739318-3074781.post@n4.nabble.com>
Message-ID: <20101207171921.GA21470@cs.cas.cz>

On Mon, Dec 06, 2010 at 08:25:39AM -0800, Alexandre wrote:
> 
> 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 :

How do you call your code? Function readline() does not wait for
user input in a non-interactive session, for example R CMD BATCH
or Rscript.

Another situation, when readline() does not wait is, when you copy
a block of code and paste it to a running session, even if it is
interactive. If readline() is not the last line of the code, then
the next line of code is used instead of the user input.

Petr Savicky.



[Rd] Wait for user input with readline()
Petr Savicky