Thanks! that's what I need. ------------ KC ^_^
On 25/11/2010, at 6:45 AM, Greg Snow wrote: > This is a user interface issue. The standard command line user interfaces > all wait for the user to hit enter before sending the information to the > parser, so this cannot be done using the standard command line interface. > > You could rewrite the source code, but that is probably overkill. The better > option is to use a different interface, there are several options, some of > which do not require much work to set up (there still is some). The windows > GUI can have the graphics device catch individual keystrokes and the Tk > interfaces (tcltk package) can do this also (plus probably others). The > playSudoku function in the sudoku package has examples of both of the above, > look at the code (the important parts are near the end of the function) and > you should be able to see ways to adapt it to your needs. > > -- > Gregory (Greg) L. Snow Ph.D. > Statistical Data Center > Intermountain Healthcare > [email protected] > 801.408.8111 > > >> -----Original Message----- >> From: [email protected] [mailto:r-help-boun...@r- >> project.org] On Behalf Of Kohleth Chia >> Sent: Wednesday, November 24, 2010 5:53 AM >> To: [email protected] >> Subject: [R] Getting user input without hitting enter >> >> 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 >> ______________________________________________ >> [email protected] mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting- >> guide.html >> and provide commented, minimal, self-contained, reproducible code. ______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.

