2

Why head and tail work differently for data.table? Is it by design?

> head(data.frame(x=1:10), -2)
  x
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
> head(data.table(x=1:10), -2)
Error in seq_len(min(n, nrow(x))) : 
  argument must be coercible to non-negative integer
> tail(data.table(x=1:10), -2)
    x
1: NA
2: NA
3: NA
4: 10
> tail(data.frame(x=1:10), -2)
    x
3   3
4   4
5   5
6   6
7   7
8   8
9   9
10 10
colinfang
  • 20,909
  • 19
  • 90
  • 173

1 Answers1

8

Yes, this was reported before, #2375. This is now fixed in v1.8.11. From NEWS:

head() and tail() handle negative 'n' values correctly now, #2375. Thanks to Garrett See for reporting. Also it results in an error when length(n) != 1. Tests added.

Arun
  • 116,683
  • 26
  • 284
  • 387