[Rd] R --interactive and readline() creates infinite loop
Jon Clayden
j.clayden at ucl.ac.uk
Fri Sep 26 22:35:52 CEST 2008
2008/9/25 Peter Dalgaard <p.dalgaard at biostat.ku.dk>:
> John Chambers wrote:
>>
>> My application, at least, wanted to show (my class) individual commands
>> from the file and then optionally insert some typed commands before going on
>> to the next part of the source file. As far as I can see, the piped shell
>> command approach will have to treat the whole file at one time.
>
> Hmmno... You can "cat -" multiple times if you want, terminating each with
> ctrl-D. That's not to say that it is the optimal solution though. Echoing
> the non-keyboard input seems a bit tricky, for instance.
Yes, looking more into it, the fact that everything gets echoed this
way is less than ideal. And for some reason, presumably to do with the
details of the behaviour of "cat", if I do
(echo 'print(readline("Input:"));q()'; cat -) | R --interactive --no-save
I need an extra newline after giving the input before I get returned
to the shell, even though R seems to have quit already. So I don't
think this is the answer. The "demoSource" approach is interesting,
but I think running two R sessions is also going to be problematic for
my application.
It really would be nice if R could do this kind of thing itself. I
would have thought it would make creating some simple "pass-through"
front-ends (like mine ;) ) very easy. I have very little knowledge of
the R source though, so I acknowledge that it may not be an easy task.
Jon
More information about the R-devel
mailing list