Repository navigation
move helper functions outside of [ #7935
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,11 @@ catf = function(fmt, ..., sep=" ", domain="R-data.table") { | |
| } | ||
|
|
||
| raise_condition = function(signal, message, classes, immediate=FALSE, appendLF=FALSE) { | ||
| obj = list(message=message, call=sys.call(sys.nframe()-2L)) | ||
| n = sys.nframe() - 2L # the caller of stopf() etc. | ||
| # helpers extracted from [.data.table are named .dt_*; their conditions report the call of [.data.table (or whoever called them) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe they should be named Another alternative to consider (especially w.r.t. potential performance drawbacks) would be to S3 them: .zip_items = function(...)
class(.zip_items) = "dt_query_helper"And here: while (inherits(sys.call(n), "dt_query_helper")) ...(I haven't tested if At a higher level, is it really that much more beneficial to see "Error in [.data.table" than "Error in .zip_items"? The latter would appear to be more specific about which of the many steps in [ went awry; and beginner users can be "scared" by "[.data.table" too (they've never written Also, be sure to evaluate the robustness of the proposed solution. I have memories of endless headaches trying to inspect the call stack and provide better errors in {bit64} where I wanted to know "Did a user call this exported S3 method directly, or did they get here from the generic?". I ultimately decided it was impossible to resolve in full generality. Edge cases to consider: |
||
| parents = sys.parents() | ||
| while (n > 0L && parents[n] > 0L && .is_dt_helper_call(sys.call(n))) n = parents[n] | ||
| obj = list(message=message, call=sys.call(n)) | ||
| # NB: append _after_ translation | ||
| if (appendLF) obj$message = paste0(obj$message, "\n") | ||
| setattr(obj, "class", classes) | ||
|
|
@@ -17,6 +21,8 @@ raise_condition = function(signal, message, classes, immediate=FALSE, appendLF=F | |
| signal(obj) | ||
| } | ||
|
|
||
| .is_dt_helper_call = function(call) is.call(call) && is.name(f <- call[[1L]]) && startsWith(as.character(f), ".dt_") | ||
|
|
||
| stopf = function(fmt, ..., class=NULL, domain="R-data.table") { | ||
| raise_condition(stop, gettextf(fmt, ..., domain=domain), c(class, "simpleError", "error", "condition")) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.