views:

91

answers:

1

I am building an user input interface in R.

onload of the program, I would like like to ask the user what their preferences are according to a set of 6 fields. This will then be used as a comparison tool for the rest of the program.

e.g.,

>ThisProgram  
>"Hello, on a scale of 1 to 10, how much would you say you rate the outdoors in your trips?    Enter a 10 for very important, and a 1 for not important at all.   
>7  
>"Great. on a scale of 1 to 10, how much would you say you rate the Family Friendly in your  trips?  Enter a 10 for very important, and a 1 for not important at all. 
>2
  .
  .
  .
  and so on...

how would I get R to ask the user a question, and then store the response in a vector?

+5  A: 

See ?readline

> x <- readline("What is your name? ")
What is your name? Josh
> x
[1] "Josh"
Joshua Ulrich
See also: `menu` for multiple choice selections and the `gWidgets*` packages for graphical user interfaces.
Richie Cotton
@Richie Cotton: Or also `tcltk` and `RGtk2` packages for generating GUIs.
nico
Nico: gWidgets* wrap around `tcltk` and `RGtk2`.
Dirk Eddelbuettel
@Dirk Eddelbuettel: oh, I did not know, always though it was a 3rd option (my bad, never really looked at it! :D)
nico
Wow... you guys are awesome. I'll be checking these out!
Zach Folwick