Hello, I would like to make my R script more interactive. Well, I want the script to work like this: I run the script from R Console and it offers me some options (press 1 for something, or press 2 for something else). After pressing 1 or 2, do corresponding procedure. I am not able to find out how to do this. I guess the functions menu() or switch() are the keys, but I didn't manage to use them properly. Can you help me? Are there some more practical examples on the web? Tahnks, Filip Kral. -- View this message in context: http://www.nabble.com/interactive-menu-in-scripts-tp15095049p15095049.html Sent from the R help mailing list archive at Nabble.com.
Hi, Not going into the reason why would you like to do such a thing anyway, I would suggest: 1. Creating an R file that would contain all the functionality coded in functions. 2. The only executed code would be a function that calls the menu() and executes the appropriate functions. Sources of existing packages provide a good reference. Have a look for example on the sources of plot.eff.list in the package 'effects'. HTH, Michal Sources of existing packa WCD wrote:> > Hello, I would like to make my R script more interactive. Well, I want the > script to work like this: > > I run the script from R Console and it offers me some options (press 1 for > something, or press 2 for something else). After pressing 1 or 2, do > corresponding procedure. > > I am not able to find out how to do this. I guess the functions menu() or > switch() are the keys, but I didn't manage to use them properly. Can you > help me? Are there some more practical examples on the web? > Tahnks, Filip Kral. >----- ____________________________________ Michal Bojanowski ICS / Department of Sociology Utrecht University Heidelberglaan 2; 3584 CS Utrecht The Netherlands m.j.bojanowski at uu dot nl http://www.fss.uu.nl/soc/bojanowski/ http://bojan.3e.pl/ -- View this message in context: http://www.nabble.com/interactive-menu-in-scripts-tp15095049p15110587.html Sent from the R help mailing list archive at Nabble.com.
Try like this: switch(menu(c("Normal", "Poisson")), rnorm(5), rpois(5, 3)) On 25/01/2008, WCD <vydramail at quick.cz> wrote:> > Hello, I would like to make my R script more interactive. Well, I want the > script to work like this: > > I run the script from R Console and it offers me some options (press 1 for > something, or press 2 for something else). After pressing 1 or 2, do > corresponding procedure. > > I am not able to find out how to do this. I guess the functions menu() or > switch() are the keys, but I didn't manage to use them properly. Can you > help me? Are there some more practical examples on the web? > Tahnks, Filip Kral. > -- > View this message in context: http://www.nabble.com/interactive-menu-in-scripts-tp15095049p15095049.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. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O