[R] Setting up infile for R CMD BATCH

Gang Chen gangchen6 at gmail.com
Wed Feb 8 03:14:51 CET 2012


Thanks for the help.

> 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).


That number '1' at the 2nd line was meant to be the answer for the
readline() part, but apparently it does not worked as I intended. If
the script ends right after the readline prompt as you suggested, my
question is, how can I feed in this answer '1' in the infile
'answers.R'?


> Just out of curiosity, why will you use a script that requires user
> input (readlines) in batch mode ?


I know this sounds contradictory, but my intention is that, in case
the user has all the answers available from a previous run in
interactive mode, s/he may try out the batch mode the next time.


> 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