Re: [R] Switch Help

2009-11-18 Thread oscar linares
Thanks for the Rxpert advice! I am up and running again... Oscar On Wed, Nov 18, 2009 at 5:57 AM, Colin Millar wrote: > I think you just missed some commas out... > > aar <- > function(command = c("scrn", "dx", "df")) > { > command <- match.arg(command) > switch(command, >scrn = cat("scr

Re: [R] Switch Help

2009-11-18 Thread Alain Guillet
I believe that is what you want: aar <-function(command) { for(i in command){ cat(i,":",switch(EXPR=i, scrn = "Screening", dx = "Diagnosis", df = "Don't Forget"), "\n") } } > aar(c("dx","df")) dx : Diagnosis df : Don't Forget Alain oscar

Re: [R] Switch Help

2009-11-18 Thread Colin Millar
And if you want to do both do invisible( lapply(c("scrn","dx"), aar) ) but I think you will have to use multiple ifs rather than switch if you intend to add more functionality... . . . I think you just missed some commas out... aar <- function(command = c("scrn", "dx", "df")) { command <-

Re: [R] Switch Help

2009-11-18 Thread Henrique Dallazuanna
If you want type twice commands in function aar, you could try this: aar <-function(command) { switch(command, scrn = cat("scrn :Screening","\n"), dx = cat("dx:Diagnosis","\n"), df = cat("df:Don't Forget","\n")) } invisible(Vectorize(aar)(c('dx', 'df'))

Re: [R] Switch Help

2009-11-18 Thread Colin Millar
I think you just missed some commas out... aar <- function(command = c("scrn", "dx", "df")) { command <- match.arg(command) switch(command, scrn = cat("scrn :Screening","\n"), dx = cat("dx:Diagnosis","\n"), df = cat("df:Don't Forget","\n") ) } Colin. Ps you don'