[R] Getting user input without hitting enter

Kohleth Chia kohleth at gmail.com
Wed Nov 24 13:53:00 CET 2010


Hi,

I am writing a function which requires user to enter a single character. Something like:

hello<-function(){
	input<-scan(n=1,what="a")
	if(input=="h")cat("Hello") # What goes after the 'if' is completely arbitrary, for simplicity sake I simply put a cat command here.
}

I want R to automatically finish scanning after the user has entered the 1st character, without hitting 'enter'.
How do I do this?



Thanks
------------
KC


More information about the R-help mailing list