[R] readline() and Rterm in Windows

Mikkel Grum mi2kelgrum at yahoo.com
Wed Nov 2 21:09:02 CET 2005


Duncan and Prof, thanks for your comments and
apologies for not being more specific. I'm not getting
the same results you get from the steps you propose.

If I write a script foo.R with two lines

	id <- readline("Please enter an ID: ")
	id

and then use source("foo.R") (either at the Rterm
prompt, or in RGui) it is true that get prompted, but
the second line does not visibly run, i.e. I get
> source("id.r")
Please enter an ID: 5
>

and if I then type id, I get
> id
[1] "id"

If I cut and paste the two lines in RGui (in one go),
I get
> id <- readline("Please enter an ID: ")
Please enter an ID: id
>

What I really want is a batch file on the desktop with
the following commands:

   c:\r\R-2.2.0\bin\Rterm.exe --no-save --no-restore
<script.R> script.out 2>&1
   c:\texmf\miktex\bin\latex
\nonstopmode\input{blue.tex}


and script.R reads something like:

   id <- readline("Please enter an ID: ")
   id
   Sweave("blue.Rnw")

I said that script.R didn't run, which was an
incorrect description. It runs without prompting for
the ID, and gives error messages all through because
blue.Rnw needs the id.

This is a very simplified version of what I'm doing,
but if I use only the first line of the batch file and
the first two lines of the script and could get that
to work, I could figure out the rest.

Mikkel



--- Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:

> What does `not work' mean here?  In particular, what
> does `running an R 
> script in' mean?
> 
> It works as I would expect: if foo.R contains
> 
>  	id <- readline("Please enter ID: ")
> 
> then
> 
> > source("foo.R")
> Please enter ID: 5
> > id
> [1] "5"
> 
> Please do read the posting guide and explain what
> you are doing it enough 
> detail for people to reproduce it.
> 
> 
> On Wed, 2 Nov 2005, Mikkel Grum wrote:
> 
> > I'm running an R script in Rterm and would like
> the
> > user to be prompted for input as in:
> >
> > id <- readline("Please enter ID: ")
> > myfunction(id)
> >
> > . . . etc.
> >
> > This works when I run one line at a time in RGui,
> but
> > not when I try to run the script in Rterm (I'm
> working
> > with R 2.2.0 in Windows Server 2003).
> >
> > Is there any way to do this?
> 
> -- 
> Brian D. Ripley,                 
> ripley at stats.ox.ac.uk
> Professor of Applied Statistics, 
> http://www.stats.ox.ac.uk/~ripley/
> University of Oxford,             Tel:  +44 1865
> 272861 (self)
> 1 South Parks Road,                     +44 1865
> 272866 (PA)
> Oxford OX1 3TG, UK                Fax:  +44 1865
> 272595
>




More information about the R-help mailing list