-
Notifications
You must be signed in to change notification settings - Fork 991
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
dcast: add argument to error on "Aggregate function missing, defaulting to 'length'" #5386
Comments
Upvoted. Any solution seems better than the current state. Even simply changing the 'message' to 'warning' would make debugging a lot easier if we've got a number of calls to dcast |
Hi , i am working on this issue
is this all that needs to be done here ? |
I agree that a warning would be more useful than a message. Rather than adding a new strict argument, I would propose just changing the message to a warning, is that OK with others? |
One free approach for downstreams is to throw on message since it is a condition: DT = data.table(a = rep(1:2, 3), b = rep(1:2, each=3L), c = 1:6)
tryCatch(dcast(DT, a ~ b, value.var="c"), message=stop) You could also accomplish this with
(or So, I'm not sure we need to do anything here. This does seem like a case for #5913 -- if we instead emitted a classed message like globalCallingHandlers(dt_missing_agg_function_message = stop) |
I would still argue it should be a warning and not a message. I have never actually wanted The approach suggested by @MichaelChirico is elegant but data.table users who are familiar with |
TBF I have wanted But would be fine with needing to provide that explicitly when needed instead of relying on it as a default. @ecoRoland2 / @Nj221102 would you like to file a PR upgrading the |
I suspect that there are quite a few real-world applications with undiscovered bugs due to this "silent default". @MichaelChirico If you are fine with that, wouldn't it follow that the default |
@MichaelChirico for now what would be better , upgrade this from a basic "message" to a "warning," or just add the deprecation message as suggested by @ecoRoland2. |
I don't think deprecation of length as default would be a good idea, that is a really big change. |
also I'm OK with not changing anything, and just using @MichaelChirico 's work-around, tryCatch(dcast(DT, a ~ b, value.var="c"), message=stop) |
I am not convinced deprecation is a good idea. Even upgrading to warning can be a breaking change (for packages and strict production scripts where |
Using In my opinion, upgrading to a warning is a breaking change. Basically, you will have to supply I would be fine if it was throwing a classed message (and in that case might even consider adding the global calling handler to my Rprofile.site). But I still think users shouldn't need to do that to get safe behavior. |
Sorry, I disagree. I really only support upgrading |
We all love seeing
Aggregate function missing, defaulting to 'length'
as it usually indicates a bug (possibly upstream resulting in unexpected input). I really need this to be an error but can't even useoptions(warn = 2)
becausedcast
only gives a message and not a warning.I suggest modifying
dcast.data.table
. One easy option would be astrict
argument that defaults toFALSE
but promotes the message to an error if set toTRUE
. If we want to avoid additional arguments, we could havefun.aggregate
acceptNA
as input with the same result.Right now the best way to catch this case appears to be
stopifnot(anyDuplicated(DT[, .(LHS, RHS)]) == 0L)
but I dislike littering my code with this.The text was updated successfully, but these errors were encountered: