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