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

Confusing warning message #2763

Closed
MichaelChirico opened this issue Apr 18, 2018 · 2 comments · Fixed by #3685
Closed

Confusing warning message #2763

MichaelChirico opened this issue Apr 18, 2018 · 2 comments · Fixed by #3685
Milestone

Comments

@MichaelChirico
Copy link
Member

MichaelChirico commented Apr 18, 2018

I'm trying to split data according to 15-minute timestamps; my approach is:

library(data.table)
set.seed(210349)
DT = data.table(t = sample(10000, 100), V = rnorm(100))
# t is in seconds, so 900 seconds is 15 minutes
DT[ , ID := .GRP, keyby = .(t %/% 900L)]

Warning message:
In [.data.table(DT, , :=(ID, .GRP), keyby = .(t%/%900L)) :
:= keyby not straightforward character column names or list() of column names, treating as a by:t%/%900

It's weird that this gives me a warning since it's purely related to the use of keyby:

# (no warning)
DT[order(t), ID := .GRP, by = .(t %/% 900L)]

(i in this case doesn't need to match that in by exactly)

For sanity:

DT[ , ID := .GRP, keyby = .(t %/% 900L)]
DT[order(t), ID2 := .GRP, by = .(t %/% 900L)]
DT[ , identical(ID, ID2)]
# [1] TRUE

What's the reason for this warning?

@franknarf1
Copy link
Contributor

I'm guessing it's that when you use := with keyby, it ...

  1. does the column edit with :=
  2. sets the key to the keyby= columns

If your keyby= columns do not exist in the table, it cannot set them as the key. Dunno if there's some clearer way to write the warning.

@MichaelChirico
Copy link
Member Author

MichaelChirico commented Apr 18, 2018 via email

MichaelChirico referenced this issue in tidyverse/dtplyr Jul 3, 2019
By using extended j expression as suggested by @MichaelChirico
@mattdowle mattdowle added this to the 1.12.4 milestone Jul 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants