switch (PR#2033)

rwehrens@sci.kun.nl rwehrens@sci.kun.nl
Tue, 17 Sep 2002 23:25:40 +0200 (MET DST)


Full_Name: Ron Wehrens
Version: 1.5.0
OS: Linux, Solaris, OSF alpha
Submission from: (NULL) (128.95.17.61)


Consider these two functions:
switchme <- function(type, ...) {
  switch(type,
         E = max(...),
         V = length(...),
         EII = sum(...),
         VII = prod(...),
         -100)
}
switchme2 <- function(type, ...) {
  switch(type,
         V = length(...),
         EII = sum(...),
         VII = prod(...),
         -100)
}
The bottom one does what I expect. The top one only gives one answer,
independent 
of the second argument.
> switchme2("V", 1:4)
[1] 4
> switchme2("X", 1:4)
[1] -100
> switchme2("EII", 1:4)
[1] 10
> switchme("V", 1:4)
[1] 24
> switchme("X", 1:4)
[1] 24
> switchme("EII", 1:4)
[1] 24
 
Is there something special about "E"?

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._