-
Notifications
You must be signed in to change notification settings - Fork 985
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
s4 objects in j groups are wrong #4415
Comments
Writing a somewhat lengthy comment here because I've been wanting somewhere to put what I've read up on and this seems to be a useful spot. I don't think this is a bug so much as a fundamental limitation of data.table. The only fully supported column types in Anything else you can (mostly2) stick in in one piece and get it out again in one piece but you can't do anything else safely. The last answer in #1777 basically explains what the issue is. It's not strictly an S4 thing but that's where it mostly crops up. Internally, simple S4 objects are stored as a vector for the first slot with all further slots stored as attributes of that vector.3 Now, Your example actually somewhat obscures the underlying issue. Replace the str(dt[ , by = period_unit, do.call(.BY$period_unit, list(period_length))][, V1])
# Formal class 'Period' [package "lubridate"] with 6 slots
# ..@ .Data : num [1:4] 0 0 0 0
# ..@ year : num 0
# ..@ month : num 0
# ..@ day : num 1
# ..@ hour : num 0
# ..@ minute: num 0 All of the slots should be length four like the first one. (NB: .Data == second) The following are all related (in no particular order and I don't make any claims that the list is exhaustive.): #2273, #4315, #4217, #2948, #1777, #3388. The last one on that list demonstrates that the issues aren't technically S4 specific. I've been having some idle thoughts on how one might tackle this but little time to actually work on it. In the meantime, a more prominent mention of the restrictions might be useful to have in the docs. 1 By scalar attribute I mean an attribute that is independent of the contents of the vector, such as a class attribute. |
Thanks, that's a great summary. A big issue with fixing this is not just that the attributes are dynamic, but that it's hard to tell in general how to apply that for a given S4 class. Can we rely on a Is there a standardized way to tell whether the class accepts vector input to |
Apologies for the second wall of text...
I don't think there is any reliable way. And in fact, such restrictions might not be properly enforced. The closest you could get would probably be attempting to parse You wouldn't need to call new. Falling back on c here to assemble the column would be enough. But as you said, it's not exactly efficient. I would say that objects that don't implement
I believe putting complicated data structures inside a data.table is fundamentally the wrong thing to do but a lot of people want to have it, so here we are. I'll share my thoughts on how to provide native support for vector objects, just in case anyone's interested:
Either way, it would be a bit of an undertaking. |
Another follow-up of #4131
j
doesn't handle S4 objects properly:The
days
object has been cascaded to the other groups.I think this is a duplicate of #1777, but I'm not sure; if so, I would close that one since I wrote this to be very direct & clear about the issue.
The text was updated successfully, but these errors were encountered: