Re: [R] interactive menu in scripts

From: WCD <vydramail_at_quick.cz>
Date: Sat, 26 Jan 2008 11:57:24 -0800 (PST)

Yes, the switch function works fine.
To store generated values in some variable I just use:   switch(menu(c("Normal", "Uniform")), a<-rnorm(5), a<-runif(5))

But why does not work this? (I know there is waste of variables, but in principle):
  b<-numeric(10)
  switch(menu(c("Normal", "Uniform")), a<-1, a<-2)   if(a==1) {b<-rnorm(10)} else {b<-runif(10)} When I run these commands from a script, the choice is offered after the condition is performed, so "b" stores ten zeros.

Also readline() function seems to be what I am looking for. But I did not manage to use it for my reason; this does not work too:   var<-numeric(5)
  rdf<-function() {
  x<-readline("Enter 1 for normal, 2 for uniform distribution ")   if (x==1) {var<-rnorm(5)} else {var<-runif(5)}   }
  rdf()

Even this does not work (object "x" is not found):   rdf2<-function() {
  x<-readline("enter your year of birth ")   }
  rdf2()

Can you see what am I doing wrong?

Anyway, I am sorry for my maybe bizzar explanations. I am quitr new to R and R forum.
My aim is to write an R script, where the user can make some choices or set some parameters via the R console. Filip Kral.

Henrique Dallazuanna wrote:
>
> Try like this:
>
> switch(menu(c("Normal", "Poisson")), rnorm(5), rpois(5, 3))
>
>
> On 25/01/2008, WCD <vydramail_at_quick.cz> wrote:

>>
>> ______________________________________________
>> R-help_at_r-project.org 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.
>>

>
>
> --
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O
>
> ______________________________________________
> R-help_at_r-project.org 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.
>
>
-- 
View this message in context: http://www.nabble.com/interactive-menu-in-scripts-tp15095049p15111894.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help_at_r-project.org 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.
Received on Sat 26 Jan 2008 - 20:02:08 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 26 Jan 2008 - 22:30:09 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive