[R] interactive prompts

Roger Bivand Roger.Bivand at nhh.no
Mon Oct 20 13:24:18 CEST 2003


On Tue, 21 Oct 2003, Ernie Adorio wrote:

> 
> Am using R on a Linux box and am currently writing an interactive R script.
> 
> 1. How do I ask a user to press any key to continue ? I used a system call to 
> read but this only works if the Enter key is pressed:
>   print("Press any key to continue")
>   system("read")

Maybe just readline("Press Enter to continue")? Why give the user the 
choice?

> 
> 2. How do I get a string input from the user? Would like to see an R function,
> say askget():
> 
>   delay  =  askget("Enter delay in seconds")
>   system(paste( "sleep ", delay))

readline(), but the return value needs to be cast from a character vector
of length one to what you need, because you can't depend on the user to
only give admissible values. Although your example is just that,
Sys.sleep()  gets you there directly.


> 
> TIA,
> 
> Ernie Adorio
> Math Department
> University of the Philippines
> Diliman, Quezon City
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Breiviksveien 40, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
e-mail: Roger.Bivand at nhh.no




More information about the R-help mailing list