[R] Getting user input without hitting enter
Greg.Snow at imail.org
Wed Nov 24 20:45:52 CET 2010
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
greg.snow at imail.org
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Kohleth Chia
> Sent: Wednesday, November 24, 2010 5:53 AM
> To: r-help at r-project.org
> Subject: [R] Getting user input without hitting enter
> I am writing a function which requires user to enter a single
> character. Something like:
> if(input=="h")cat("Hello") # What goes after the 'if' is
> completely arbitrary, for simplicity sake I simply put a cat command
> I want R to automatically finish scanning after the user has entered
> the 1st character, without hitting 'enter'.
> How do I do this?
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help