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

John Chambers jmc at r-project.org
Thu Sep 25 15:13:59 CEST 2008


For an alternative approach to your original goal, take a look at 
demoSource() in the SoDA package from CRAN.  It's a bit tedious to set 
up (see the Details section of the help file) but uses standard R 
sessions to mix lines from a demo file and interactive input.

John

Jon Clayden wrote:
> 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/
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



More information about the R-devel mailing list