data.table
是一个精彩包,其中,唉,从checkUsage
产生无理警告(代码来自here和here):data.table不与checkUsage发挥出色
> library(compiler)
> compiler::enableJIT(3)
> dt <- data.table(a = c(rep(3, 5), rep(4, 5)), b=1:10, c=11:20, d=21:30, key="a")
> my.func <- function (dt) {
dt.out <- dt[, lapply(.SD, sum), by = a]
dt.out[, count := dt[, .N, by=a]$N]
dt.out
}
> checkUsage(my.func)
<anonymous>: no visible binding for global variable ‘.SD’ (:2)
<anonymous>: no visible binding for global variable ‘a’ (:2)
<anonymous>: no visible binding for global variable ‘count’ (:3)
<anonymous>: no visible binding for global variable ‘.N’ (:3)
<anonymous>: no visible binding for global variable ‘a’ (:3)
> my.func(dt)
Note: no visible binding for global variable '.SD'
Note: no visible binding for global variable 'a'
Note: no visible binding for global variable 'count'
Note: no visible binding for global variable '.N'
Note: no visible binding for global variable 'a'
a b c d count
1: 3 15 65 115 5
2: 4 40 90 140 5
约a
该警告可以是通过用by="a"
代替by=a
而避免,但我如何处理其他3个警告?
这对我很重要,因为这些警告混乱了屏幕并掩盖了合法的警告。由于警告是在my.func
调用(启用JIT编译器时)上发出的,而不是仅由checkUsage
发出,所以我倾向于将其称为bug。
查询:那些是my.func内的对象,那么为什么它们应该被认为是'global'变量呢? – 2013-04-23 14:53:58
请参见[this](http://stackoverflow.com/a/15411032/967840)和[this](http://stackoverflow.com/a/8096882/967840) – GSee 2013-04-23 14:57:52
我不知道'checkUsage'。如果有什么我可以在'data.table'中修改的,请告诉我。或者,也许有一个选择'checkUsage'。 – 2013-04-23 15:12:58