R:区分 EMPTY 省略号和包含 NULL 的省略号?

bal*_*lin 2 r ellipsis

想象:

myfunct <- function(x, ...){
  dots <- list(...)
...
}
Run Code Online (Sandbox Code Playgroud)

如何在函数过程中区分点是从myfunct('something')(无点)还是myfunct('something', NULL)(点包括显式NULL)派生的?在我的实验两种情况下会导致is.null(dots)等同于TRUE

Sté*_*ent 5

它有帮助吗?

f <- function(x, ...){
  missing(...)
}
> f(2)
[1] TRUE
> f(2, NULL)
[1] FALSE

g <- function(x, ...){
  length(list(...))
}
> g(2)
[1] 0
> g(2, NULL)
[1] 1
Run Code Online (Sandbox Code Playgroud)