Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setDT method for tbl_df class #1078

Closed
jangorecki opened this issue Mar 13, 2015 · 1 comment
Closed

setDT method for tbl_df class #1078

jangorecki opened this issue Mar 13, 2015 · 1 comment
Assignees
Milestone

Comments

@jangorecki
Copy link
Member

Output of many function in dplyr pkg is a tbl_df class objects. It is not handled correctly by setDT which works on regular df and lists very well. See below:

packageVersion("dplyr")
# [1] ‘0.4.1’
packageVersion("data.table")
# [1] ‘1.9.5’
library(dplyr) # latest CRAN
library(data.table) # latest dev

df <- data.frame(a = rnorm(1000), b = sample(1:5,1000,TRUE))
class(df)
# [1] "data.frame"
df2 <- as.tbl(df)
class(df2)
# [1] "tbl_df"     "tbl"        "data.frame"
setDT(df2)
class(df2)
# [1] "tbl_df"     "tbl"        "data.table" "data.frame"

Would be great to have setDT works on tbl_df and possibly also tbl classes.
Currently such object is not usable without using first setDT(as.data.frame(df2))[].

Edit
Or easier/faster operating directly on class attribute: setattr(df,"class",c("data.table","data.frame"))

@arunsrinivasan
Copy link
Member

#1128 also seems related. Possible fix is as follows:

  • If an object is already a data.table with additional classes, we retain in any and all operations possible (current behaviour as such need not be modified).
  • If an object is converted from another object to data.table, then we simply do not retain classes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants