Repository navigation
rowwiseDT support for key #7940
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 1 commit
0cff4c9
8e8b3f5
002d5ed
d7d5b4f
d34e643
f755662
d8864d9
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 |
|---|---|---|
|
|
@@ -2,11 +2,23 @@ | |
| x = substitute(list(...))[-1L] | ||
| if (is.null(nms <- names(x))) | ||
| stopf("Must provide at least one column (use `name=`). See ?rowwiseDT for details") | ||
| if (length(key_pos <- which(nms == "key" & nzchar(x))) > 0L) { | ||
| if (length(key_pos) > 1L) | ||
| stopf("key specified more than once") | ||
| if (length(key <- eval(x[[key_pos]], parent.frame())) == 1L) | ||
| key = cols_from_csv(key) | ||
| x = x[-key_pos] | ||
| nms = nms[-key_pos] | ||
| } else { | ||
| key_pos = 0L | ||
| } | ||
| header_pos = which(nzchar(nms)) | ||
| if (any(nzchar(x[header_pos]))) | ||
| stopf("Named arguments must be empty") | ||
| if (!identical(header_pos, seq_along(header_pos))) | ||
| stopf("Header must be the first N arguments") | ||
| if (key_pos && !(key_pos - 1L) %in% c(0L, length(header_pos), length(x))) | ||
|
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. why (it can be a bit hard to map the test case to how it might look in "real" code, so I might be missing something, although this was something mentioned by me as 'bad' in #7905) test(2282.11, rowwiseDT(A=, B=, key="B", 1, 2), DT)
Contributor
Author
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. It is because I imagined data.table(a=.., b=.., key = "a") plus a data block, but I agree the extra flexibility is not very worthy here. I'll remove the middle option. |
||
| stopf("key specification not allowed in between names or data, only boundaries") | ||
| header = nms[header_pos] | ||
| ncols = length(header) | ||
| body = lapply(x[-header_pos], eval, envir = parent.frame()) | ||
|
|
@@ -27,5 +39,7 @@ | |
| body = split(body, rep(seq_len(nrows), each = ncols)) | ||
| ans = rbindlist(body) | ||
| setnames(ans, header) | ||
| if (key_pos) | ||
|
MichaelChirico marked this conversation as resolved.
Resolved
|
||
| setkeyv(ans, key) | ||
| ans | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.