[R] Setting up infile for R CMD BATCH

ilai keren at math.montana.edu
Wed Feb 8 01:04:27 CET 2012


You're not missing anything.
In your output.Rout: the ">1" right after the source('test') is the
"1" inputed from answers.R. the "[1] 1" is the result of test. Remove
the second line from answers.R and see what happens (hint: script ends
after the readline prompt).
Just out of curiosity, why will you use a script that requires user
input (readlines) in batch mode ?
Cheers



On Tue, Feb 7, 2012 at 4:05 PM, Gang Chen <gangchen6 at gmail.com> wrote:
> Suppose I create an R program called myTest.R with only one line like
> the following:
>
> type <- as.integer(readline("input type (1: type1; 2: type2)? "))
>
> Then I'd like to run myTest.R in batch mode by constructing an input
> file called answers.R with the following:
>
> source("myTest.R")
> 1
>
> When I ran the following at the terminal:
>
> R CMD BATCH answer.R output.Rout
>
> it failed to pick up the answer '1' from the 2nd line in answers.R as
> shown inside output.Rout:
>
>> source("myTest.R")
> input type (0: quit; 1: type1; 2: type2)?
>> 1
> [1] 1
>
> What am I missing here?
>
> Thanks in advance,
> Gang
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list