data.table
is a wonderful package, which, alas, generates unwarranted warnings from checkUsage
(the code comes from here and here):
> 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
The warnings about a
can be avoided by replacing by=a
with by="a"
, but how do I deal with the other 3 warnings?
This matters to me because these warnings clutter the screen and obscure legitimate warnings. Since the warnings are issued on my.func
invocation (when JIT compiler is enabled), not just by checkUsage
, I am inclined to call this a bug.