提供没有值的命名参数,它们会进入下一个有值的表达式
> switch("A", A=, B=, C="A OR B OR C", "Other")
[1] "A OR B OR C"
> switch("C", A=, B=, C="A OR B OR C", "Other")
[1] "A OR B OR C"
> switch("D", A=, B=, C="A OR B OR C", "Other")
[1] "Other"
这在帮助页面上有描述?switch
If 'EXPR' evaluates to a character string then that string is
matched (exactly)to the names of the elements in '...'. If there
is a match then that element is evaluated unless it is missing, in
which case the next non-missing element is evaluated, so for
example 'switch("cc", a = 1, cc =, cd =, d = 2)' evaluates to '2'.