data.table与checkUsage不匹配

sds*_*sds 10 r data.table

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
Run Code Online (Sandbox Code Playgroud)

有关这些警告a可以通过更换避免by=aby="a",但我该如何处理与其他3个警告?

这对我很重要,因为这些警告会使屏幕变得混乱并掩盖合法的警告.由于警告是在my.func调用时发出的(当启用JIT编译器时),而不仅仅是checkUsage,我倾向于将此称为错误.

Mat*_*wle 6

更新:现在在v1.8.11中已解决。来自新闻

.SD.N.I.GRP.BY现已出口(如NULL)。这样便不会通过R CMD checkcodetools::checkUsage通过为它们生成NOTE compiler::enableJIT()utils::globalVariables()考虑过,但选择了出口。感谢Sam Steingold提出的#2723

为了解决列名符号count和的注释a,它们都可以用引号引起来(即使在的LHS上也是如此:=)。使用新的R会话(因为注释仅是第一次),以下内容现在不产生注释。

$ R
R version 3.0.1 (2013-05-16) -- "Good Sport"
Copyright (C) 2013 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
> require(data.table)
Loading required package: data.table
data.table 1.8.11  For help type: help("data.table")
> library(compiler)
> compiler::enableJIT(3)
[1] 0
> 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
}
> my.func(dt)
   a  b  c   d count
1: 3 15 65 115     5
2: 4 40 90 140     5
> checkUsage(my.func)
> 
Run Code Online (Sandbox Code Playgroud)