If you look at internal code of switch
in file src/main/builtin.c, you can read in lines 1009-1025 :
This is a SPECIALSXP, so arguments need to be evaluated as needed.
SPECIALSXP
means :
no SEXPTYPE Description
7 SPECIALSXP special functions
So switch
is actually a special function which passes unevaluated arguments to the internal function.
Further reading the source code from line 1030 to line 1104 shows that as explained in ?switch
, the function either handles character
or number
in a simple and not fully optimized way.
This probably explains why switch
isn't particularly fast in situations which would for example require a binary search.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…