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

data.table's := prints when data.table is not the first class #1054

Closed
rubenarslan opened this issue Apr 1, 2015 · 2 comments
Closed

data.table's := prints when data.table is not the first class #1054

rubenarslan opened this issue Apr 1, 2015 · 2 comments

Comments

@rubenarslan
Copy link

I left this as a comment on a closed data.table issue previously, that probably was a bad idea. I think this might have to be fixed on the dplyr side, since the solution in data.table lives in the print.data.table function, which isn't called when "grouped_dt" is in the pole position.

The bug Rdatatable/data.table#505 happens when e.g. dplyr::group_by was used on a data.table. Presumably the error can also occur when other classes remove data.table from being the pole position class.

Here's a failing test:

cat(knit(text='`:=` prints in conjunction with dplyr, because dplyr adds all kind of classes to data.tables

```{r}
library(dplyr); library(data.table)
mtcars = data.table(mtcars)

grouped = mtcars %>% group_by(cyl)
grouped[, mpg := 2]
class(grouped)

class(grouped) = c("data.table", "grouped_dt", "tbl_dt", "tbl", "data.frame") # reorder classes
grouped[, mpg := 2]

    # this is how I currently "fix" it.
grouped = mtcars %>% group_by(cyl) %>% data.table()
grouped[, mpg := 2]
class(grouped)
```'))

This is with data.table_1.9.5, dplyr_0.4.1 and knitr_1.9.

@hadley
Copy link
Member

hadley commented May 19, 2015

I'm extending the data table class so I'm pretty sure my class names should come first.

@hadley hadley closed this as completed May 19, 2015
@rubenarslan
Copy link
Author

Sorry, I didn't mean to suggest your class names shouldn't come first – but if dplyr is extending the dt class, it would be better if printing didn't break when dt functionality (:=) is later used.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants