[R] readline() and Rterm in Windows

Duncan Murdoch murdoch at stats.uwo.ca
Wed Nov 2 18:17:18 CET 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?

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




More information about the R-help mailing list