I am using data.table and dplyr together. I recently noticed dplyr::group_by can also set key to a data.table object.
# R version 3.1.0
library(data.table) # 1.9.2
library(dplyr) # 0.1.3
dt <- data.table(A=rep(c("a", "b"), times=c(2, 3)), B = rep(1, 5))
tables()
# NAME NROW MB COLS KEY
# [1,] dt 5 1 A,B
# Total: 1MB
group_by(dt, A)
tables()
# NAME NROW MB COLS KEY
# [1,] dt 5 1 A,B A
# Total: 1MB
I am wondering why this happens. Is this intended? as I know Hadley is trying to make dplyr compatible with data.table.
(If possible, I would also like to know how key is implemented in data.table. Very curious about why setkey can change it inplace?)
Thanks
Per G. Grothendieck's request:
library(data.table)
dt <- data.table(A = rep(c("a", "b"), times=c(2, 3)),
B = rep(1, 5))
dplyr::group_by(dt, A)
# Source: local data table [5 x 2]
# Groups: A
#
# Error in if (is.na(rows) || rows > getOption("dplyr.print_max")) { :
# missing value where TRUE/FALSE needed
tables()
# NAME NROW MB COLS KEY
# [1,] dt 5 1 A,B A
# Total: 1MB
I use these two packages quite often, I would like to know all details so to avoid mistakes.