[R] Command-line arguments and --interactive

Adam D. I. Kramer adik at ilovebacon.org
Tue Nov 10 20:04:41 CET 2009


On Tue, 10 Nov 2009, Duncan Murdoch wrote:

> --interactive tells R that there is a human producing the input stream, so it 
> can ask questions and expect them to be answered.  In your experiments with 
> it, your input stream was the pipe holding the output of echo, and R got 
> confused because that pipe wouldn't answer its question.

I see. That makes sense, and thank you.

> Your problem is that you want an input stream that starts out from your
> fixed code and then switches to your shell's stdin.

Correct. Or, you might consider it an ability to add a command or two to the
effective end of .Rprofile.

> I think you can do that on some systems by saving your input to a file
> then concatenating it to stdin, e.g.  something like this:
>
> echo '10*5; scan()' >test.R
> cat test.R - | R --interactive
>
> I don't know if there's a way to do this in one line, and I'd expect some 
> oddities.

Creating a new file progammatically is difficult.

Another solution, suggested by peterdc in the #R irc channel, was to run R
itself and then use the system() command to complete the
prior-to-launching-R task...that is the solution I'm going with, but thanks
very much for your help!

--Adam




More information about the R-help mailing list