[R] Setting up infile for R CMD BATCH

Gang Chen gangchen6 at gmail.com
Wed Feb 8 00:05:22 CET 2012


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



More information about the R-help mailing list