Re: [Rd] bug of *switch* function

2009-03-09 Thread Stavros Macrakis
On Mon, Mar 9, 2009 at 8:55 AM, guangchuang yu asked why switch(..., a <- 3, ...) doesn't have the same effect as switch(..., a=3, ...). In most contexts, `<-` and `=` are synonymous in R, and mean assignment. In function-argument position, however, an infix `=` names the argument. Switch depend

Re: [Rd] bug of *switch* function

2009-03-09 Thread Josh Ulrich
Because "<-" assigs a value. It does not name the alternatives. Again, please read ?switch. These two examples are the same: > organism <- 'foo' > (species <- switch(organism, human <- "HS", fly <- "DM", yeast <- "SC")) [1] "HS" > (species <- switch(organism, "HS", "DM", "SC")) [1] "HS" Josh --

Re: [Rd] bug of *switch* function

2009-03-09 Thread guangchuang yu
But Why ? Why can not use "<-" ? On Mon, Mar 9, 2009 at 10:31 PM, Jeff Ryan wrote: > This isn't a bug in R. > > You are assigning within the switch statement, and it is returning the > first TRUE value (human). > > Use "=" not "<-" > > species <- switch(organism, human="HS", fly="DM", yeast="SC

Re: [Rd] bug of *switch* function

2009-03-09 Thread Jeff Ryan
This isn't a bug in R. You are assigning within the switch statement, and it is returning the first TRUE value (human). Use "=" not "<-" species <- switch(organism, human="HS", fly="DM", yeast="SC") > species [1] "SC" HTH Jeff On Mon, Mar 9, 2009 at 8:55 AM, guangchuang yu wrote: > Hi, > > W

Re: [Rd] bug of *switch* function

2009-03-09 Thread Peter Dalgaard
guangchuang yu wrote: > Hi, > > When I call the *switch* function first time, it works. but when I call it > at the second time, it does nothing. The version I use is R version 2.9.0 > Under development (unstable) (2009-02-21 r47969) > > > here is the output: > >> organism="human" >> specie

[Rd] bug of *switch* function

2009-03-09 Thread guangchuang yu
Hi, When I call the *switch* function first time, it works. but when I call it at the second time, it does nothing. The version I use is R version 2.9.0 Under development (unstable) (2009-02-21 r47969) here is the output: > organism="human" > species <- switch(organism, human <- "Hs