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? Mikkel
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?It works for me. What goes wrong when you try it? (And how exactly are you executing the script?) If you're trying something like Rterm <script.R it will fail, because readline will read from the file. But if you use source() in Rterm, it should do what you want. Duncan Murdoch
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