[R] User input when running R code in batch mode
b.rowlingson at lancaster.ac.uk
Tue Oct 27 10:17:24 CET 2009
On Tue, Oct 27, 2009 at 9:20 AM, Kaushik Krishnan
<kaushik.s.krishnan at gmail.com> wrote:
> $ r --vanilla < test.r
>> a <- scan(what='character',n=1); a
> 1: Read 0 items
> Now it's not working.
Assuming this is a unix environment, the syntax '< test.r' means 'my
standard input stream is the file test.r'. That's not what you want.
Give R the file name as an argument and let the standard input stream
remain user input:
$ r --vanilla test.r
Read 1 item
Note that this is 'r' and not 'R'. For me this comes from the
'littler' package in Ubuntu Linux. The same thing with 'R' doesn't
$ R --vanilla test.r
ARGUMENT 'test.r' __ignored__
> [the R prompt appears]
Maybe there's a way of doing this with big R, but I think littler is
designed for this kind of thing.
> Is there any way to make R stop for the user to enter values when
> running in batch mode either by changing the way I invoke scan() or
> readLines() or by using any other function?
An alternative is to use the tcltk package to make a dialog for user input.
More information about the R-help