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

Check if input is data.frame #32

Closed
ghost opened this issue Oct 2, 2015 · 3 comments
Closed

Check if input is data.frame #32

ghost opened this issue Oct 2, 2015 · 3 comments

Comments

@ghost
Copy link

ghost commented Oct 2, 2015

I often work with data.frames and data.tables side by side as some commands written for a data.frame get a hickup with data.tables. So does dust(). So maybe a tiny input check for data.frames? Or for (accidentally) inputted data.table do just a quick conversion to data.frame? [Note: this might be related to the considerations in #6.]

DT = data.table(ID = c("b","b","b","a","a","c"), a = 1:6, b = 7:12, c=13:18)
dust(DT)
#> Error in `:=`(row, 1:.N): Check that is.data.table(DT) == TRUE. Otherwise, := and `:=`(...) are defined for use in j, once only and in particular ways. See help(":=").
df <- as.data.frame(DT)
dust(df)
#>   ID a  b  c
#> 1  b 1  7 13
#> 2  b 2  8 14
#> 3  b 3  9 15
#> 4  a 4 10 16
#> 5  a 5 11 17
#> 6  c 6 12 18
@nutterb
Copy link
Owner

nutterb commented Oct 3, 2015

Great catch. It seems that data.tables don't take well to dplyr::gather. I've included a line that will coerce any object that inherits data.table to a data frame. That should take care of it for you.

The patch is in the latex-tables branch. I'll move it up into the main branch when I get some more features put in. You should see this correction on CRAN around the middle of the month.

@nutterb nutterb closed this as completed Oct 3, 2015
nutterb added a commit that referenced this issue Oct 3, 2015
@ghost
Copy link
Author

ghost commented Oct 10, 2015

Great, thank you!
[Think that is tidyr::gather (not dyplyr::gather)? Otherwise we should let Hadley know, because dplyr is supposed to work with data.tables too.]

@nutterb
Copy link
Owner

nutterb commented Oct 10, 2015

Yes, it should have been tidyr::gather, and after looking at it some more, it might actually be the combination of dplyr::mutate and data.table. See tidyverse/dplyr#1431 and Rdatatable/data.table#1366. I'm at a loss for what the issue might be, but for now, I guess I'll have to coerce to a data frame. I'll keep an eye on it so that sometime in the future I might be able to avoid the coercion.

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

No branches or pull requests

1 participant