From j.clayden at ucl.ac.uk  Wed Sep 24 14:36:13 2008
From: j.clayden at ucl.ac.uk (Jon Clayden)
Date: Wed, 24 Sep 2008 13:36:13 +0100
Subject: [Rd] R --interactive and readline() creates infinite loop
Message-ID: <98A53690-6407-4E86-A094-27707C77C744@ucl.ac.uk>

Dear all,

I have asked before, in R-help [1], about a way to create an  
interactive session in which commands are taken from a file or  
standard input - like R CMD BATCH but additionally allowing user input  
- but there was no response to that question, and the workarounds that  
I have found (using "expect", creating a temporary .Rprofile) are ugly  
and problematic.

With the appearance of the --interactive flag in R 2.7.0 I thought  
this might become possible, but it not only does not behave as I would  
expect, it appears to go into an infinite loop, and uses 100% CPU  
until killed.

$ echo 'print(readline("Input:"))' | R --no-save --quiet
 > print(readline("Input:"))
Input:[1] ""
 >
[no interactivity]

$ echo 'print(readline("Input:"))' | R --no-save --quiet --interactive
[no response at all]

This behaviour remains in the latest alphas of R 2.8.0. My platform is  
Mac OS X.5.5 on Intel Core 2 Duo.

I assume, given this outcome, that this is not the intended use of -- 
interactive, but I still wonder if there is any way to achieve an  
interactive session based on a predefined set of commands without  
writing a completely new front-end (overkill, surely?).

Any guidance would be appreciated.

Regards,
Jon

[1] http://finzi.psych.upenn.edu/R/Rhelp02a/archive/117412.html


--
Jonathan D. Clayden, Ph.D.
Research Fellow
Radiology and Physics Unit
UCL Institute of Child Health
30 Guilford Street
LONDON  WC1N 1EH
United Kingdom

t | +44 (0)20 7905 2708
f | +44 (0)20 7905 2358
w | www.homepages.ucl.ac.uk/~sejjjd2/



[Rd] R --interactive and readline() creates infinite loop
Jon Clayden