-
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 7 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,22 @@ 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( | ||
| body, | ||
| function(v) !is.atomic(v) && !is.null(v) && typeof(v) != "list", | ||
| FUN.VALUE = logical(1L) | ||
| ) | ||
| 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 = typeof(body[[first_problem_idx]]) | ||
|
||
| stopf( | ||
| "In column '%s', received an object of type '%s'.\nComplex objects (like functions, models, etc.) must be wrapped in list() to be stored in a data.table column.\nPlease use `list(...)` for this value.", | ||
|
||
| 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.
is this check really what @aitap wrote about catering for that
is.atomic(NULL)=TRUEon older R versions?it should also be faster to check
!(is.atomic(v) || is.null(v) || typeof(v) == "list")Note that we have our internal versions of vapply e.g.
vapply_1b