I noticed that .N was made available in i recently, so I started using the feature. However, I got into trouble when trying to use .N in nested data tables. Here's an example:
require(data.table)
tbl = data.table(1:5)
tbl[1:.N]
# V1
#1: 1
#2: 2
#3: 3
#4: 4
#5: 5
tbl[, head(.SD, n=2)[1:.N]]
# V1
#1: 1
#2: 2
#3: NA
#4: NA
#5: NA
tbl[, head(.SD, n=2)[, 1:.N]]
# [1] 1 2
I was expecting .N in both i and j to bind to the most local data.table environment. In this case, the nested table, so .N=2.
I brought this issue up with Arun. He looked at the code and found that .N was locked to the top-level data.table. He thought this would be a good issue to bring to the community for discussion.
-Clayton
I noticed that
.Nwas made available in i recently, so I started using the feature. However, I got into trouble when trying to use.Nin nested data tables. Here's an example:I was expecting
.Nin bothiandjto bind to the most localdata.tableenvironment. In this case, the nested table, so.N=2.I brought this issue up with Arun. He looked at the code and found that
.Nwas locked to the top-leveldata.table. He thought this would be a good issue to bring to the community for discussion.-Clayton