I would be interested to know if there is a way to avoid the generation of NAs when subsetting .SD with an index larger than its number of rows, rather than having to remove them in a second step.
I only see a way to remove NA in a second step, ex. using na.omit.
data.table(A = 1)[ , .SD[1:2]]
## A
## 1: 1
## 2: NA
# this is what I do now, removing NAs in a second step
na.omit(data.table(A = 1)[ , .SD[1:2]])
## A
## 1: 1