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

gfirst(.SD) throws an error about not using head(.SD, n), but the latter works #2030

Closed
franknarf1 opened this issue Feb 16, 2017 · 0 comments · Fixed by #3463
Closed

gfirst(.SD) throws an error about not using head(.SD, n), but the latter works #2030

franknarf1 opened this issue Feb 16, 2017 · 0 comments · Fixed by #3463
Assignees
Labels
bug GForce
Milestone

Comments

@franknarf1
Copy link
Contributor

@franknarf1 franknarf1 commented Feb 16, 2017

I tried this and got an error:

library(data.table)
DT = data.table(id = c(1L,1L,2L), v = 1:3)
DT[, first(.SD), by=id, .SDcols="v", verbose = TRUE]
# Finding groups using forderv ... 0 sec
# Finding group sizes from the positions (can be avoided to save RAM) ... 0 sec
# lapply optimization is on, j unchanged as 'first(.SD)'
# GForce optimized j to 'gfirst(.SD)'

Error in gfirst(.SD) :
GForce head can only be applied to columns, not .SD or similar. To get head of all items in a list such as .SD, either add the prefix utils::head(.SD) or turn off GForce optimization using options(datatable.optimize=1).

I tried head and it did work, contrary to the error message:

DT[, head(.SD, 1L), by=id, .SDcols="v", verbose=TRUE]
# Finding groups using forderv ... 0.02 sec
# Finding group sizes from the positions (can be avoided to save RAM) ... 0 sec
# lapply optimization changed j from 'head(.SD, 1L)' to 'list(head(v, 1L))'
# GForce optimized j to 'list(ghead(v, 1L))'
# Making each group and running j (GForce TRUE) ... 0 secs
#    id v
# 1:  1 1
# 2:  2 3

Not a big deal and maybe it'll be handled in the process of of doing #735

@MichaelChirico MichaelChirico added the GForce label Feb 25, 2019
@jangorecki jangorecki self-assigned this Mar 17, 2019
@mattdowle mattdowle added this to the 1.12.4 milestone Apr 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug GForce
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants