-
Notifications
You must be signed in to change notification settings - Fork 1k
rowwise(): Detect and reject non-atomic, non-list column values with clear error message #7250
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
base: master
Are you sure you want to change the base?
Changes from all commits
aaa09aa
2110d98
6b271bb
2f777d5
d19bc2a
dd36cf7
08fe92e
669f6ad
3ece463
e2de9c0
dddcedb
dafc34f
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 | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,6 +13,21 @@ rowwiseDT = function(...) { | |||||||||||||||||
| nrows = length(body) %/% ncols | ||||||||||||||||||
| if (length(body) != nrows * ncols) | ||||||||||||||||||
| stopf("There are %d columns but the number of cells is %d, which is not an integer multiple of the columns", ncols, length(body)) | ||||||||||||||||||
| is_problematic = vapply_1b( | ||||||||||||||||||
| body, | ||||||||||||||||||
| function(v) !(is.atomic(v) || is.null(v) || typeof(v) == "list") | ||||||||||||||||||
| ) | ||||||||||||||||||
| if (any(is_problematic)) { | ||||||||||||||||||
| first_problem_idx = which(is_problematic)[1L] | ||||||||||||||||||
| col_idx = (first_problem_idx - 1L) %% ncols + 1L | ||||||||||||||||||
| col_name = header[col_idx] | ||||||||||||||||||
| obj_type = class1(body[[first_problem_idx]]) | ||||||||||||||||||
|
Comment on lines
+21
to
+24
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.
Suggested change
Would feel more consistent to our codebase/ |
||||||||||||||||||
| stopf( | ||||||||||||||||||
| "In column '%s', received an object of type '%s'.\nComplex objects (like functions, formulas, or calls) must be wrapped in list() to be stored in a data.table column.\nPlease use `list(...)` for this value.", | ||||||||||||||||||
|
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. The indent is off, see e.g. > rowwiseDT(x =, func =, 1, \(x) x + 1)
Error in rowwiseDT(x = , func = , 1, function(x) x + 1) :
In column 'func', received an object of type 'function'.
Complex objects (like functions, formulas, or calls) must be wrapped in list() to be stored in a data.table column.
Please use `list(...)` for this value.
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 also something more in the direction of stopf("Column '%s' is type '%s'. Non-atomic, non-list objects must be wrapped in list(), e.g., list(f) instead of f", col_name, obj_type) |
||||||||||||||||||
| col_name, | ||||||||||||||||||
| obj_type | ||||||||||||||||||
| ) | ||||||||||||||||||
| } | ||||||||||||||||||
| # make all the non-scalar elements to a list | ||||||||||||||||||
| needs_list = lengths(body) != 1L | ||||||||||||||||||
| body[needs_list] = lapply(body[needs_list], list) | ||||||||||||||||||
|
|
||||||||||||||||||
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.
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.
Ofc, it must also be moved to the
1.18.99NEWS section