r - R:区分 EMPTY 省略号和包含 NULL 的省略号?
问题描述
想象:
myfunct <- function(x, ...){
dots <- list(...)
...
}
如何在函数过程中区分点是从myfunct('something')
(无点)还是myfunct('something', NULL)
(点包括显式NULL
)派生的?在我的实验中,这两种情况都导致is.null(dots)
等同于TRUE
.
解决方案
它有帮助吗?
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
推荐阅读
- postgresql - 加速查询日期变量
- visual-studio-code - Visual Studio Code,如何使本地文件链接打开默认程序
- python - 在Python中,如何计算多列中高于一列元素的元素数量?
- javascript - 使用 setInterval 在我的游戏中的敏感性不起作用(js)
- c# - 在 C# 测试方法中使用 for 循环生成 DataRow 参数
- android - 单击onBackPressed按钮后AppBarLayout无法显示
- python-3.x - 如何解决 workon:commnad not found for virtualenv?
- html - ngAfterViewInit 更改时,Angular 不会将值更新为 View
- ios - 当嵌套的 UITextView 开始编辑时,UICollectionView 跳转/滚动
- javascript - dataframe.js - 是否可以对分组数据框中的多列求和?