when I recalled the switch function, it always gave the first element, no matter what the parameter is.

r-29-dev

when organism changed to “yeast”, and called switch function, species supposed to be changed to “Sc”, but it remains it’s original value.

After I read the manual, I change “<-” to “=”, and it works as I expected.

r-29-switch

In R, the assignment token is “<-” but not “=”. “=” is equivalent to “<-” when assign a value. At this time, it’s not to assign a value but to name an alternative.

It’s curious but this is the syntax of R.

The authors of R once said: syntax is superficial.

I know syntax is not the essential of a language, but it’s the way how we express our ideas. At this point, it’s the most important thing. This maybe the reason why they chose S as the syntax of R, since S is designed for statistical computing.

I really hate the syntax sometimes.

Here is the explanation from ‘The R Inferno’ page 78 assign