首页 > 解决方案 > R:区分 EMPTY 省略号和包含 NULL 的省略号?

问题描述

想象:

myfunct <- function(x, ...){
  dots <- list(...)
...
}

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

标签: rellipsis

解决方案


它有帮助吗?

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

推荐阅读