Mauricio Cornejo
2012-Dec-03 18:52 UTC
[R] switch() vs eval() for choosing pre-existing alternatives?
Can anyone explain (perhaps with an example) why the R Language Definitions (Version 2.15.2, 2012-10-26, DRAFT) says the following in section 3.2.6? "To choose from a list of alternatives that already exists switch() may not be the best way to select one for evaluation. It is often better to use eval() and the subset operator, [[, directly via eval(x[[condition]])." I can't quite figure out the reasoning behind the recommendation or how to make good use of it. Many thanks, Mauricio [[alternative HTML version deleted]]
Apparently Analagous Threads
- How to use 'switch' with strings containing spaces?
- Problems understanding use of regular expression (in gsub) for manipulating currency
- How to use access results of gregexpr in data frames
- Inexplicably different results using subset vs bracket notation on logical variable
- How to subset based on column name that is a number ?