Skip to content
Prev 8054 / 63424 Next

switch (PR#2033)

rwehrens@sci.kun.nl writes:
Yes. It matches the EXPR arg to switch using partial matching, so the
case selector becomes max(1:4) == 4 and the fourth case is used to gie
prod(1:4) == 24. Not a bug, although perhaps a feature regretted by
the inventor...

The workaround (except for avoiding case labels E, EX, EXP) is 

switchme <- function(type, ...) {
  switch(EXPR=type,
         E = max(...),
         V = length(...),
         EII = sum(...),
         VII = prod(...),
         -100)
}