Document how j results are combined with by via rbindlist (issue #7643)#7651
Document how j results are combined with by via rbindlist (issue #7643)#7651mahjabinoyshi wants to merge 2 commits intoRdatatable:masterfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7651 +/- ##
=======================================
Coverage 99.02% 99.02%
=======================================
Files 87 87
Lines 16897 16897
=======================================
Hits 16733 16733
Misses 164 164 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Why not to give explanation in rbindlist a d just refer that by uses rbindlist internally? ?data.table is already so big |
|
@jangorecki Thanks for the feedback! I’m happy to move most of the explanation to ?rbindlist instead. 1)In ?data.table, shorten the new text to something like: Will it be okay? |
|
this text is too long, please shorten. |
|
and please remove test case |
|
@tdhock I’ve updated the PR to shorten the by documentation, kept the new sentence within the by argument section, and removed the test case as requested. |
| \emph{Advanced:} In the \code{X[Y, j]} form of grouping, the \code{j} expression sees variables in \code{X} first, then \code{Y}. We call this \emph{join inherited scope}. If the variable is not in \code{X} or \code{Y} then the calling frame is searched, its calling frame, and so on in the usual way up to and including the global environment. | ||
|
|
||
| When \code{by} is supplied, per-group \code{j} results are combined using | ||
| \code{\link{rbindlist}}; see its help for details on how columns and names |
There was a problem hiding this comment.
there are still line breaks, please remove.
Also I think this should be moved up closer to the sentence that describes group order.
by: Column names are seen as if they are variables (as in 'j' when 'with=TRUE'). The 'data.table' is then grouped by the 'by' and 'j' is evaluated within each group. The order of the rows within each group is preserved, as is the order of the groups. The results are combined using \code{\link{rbindlist}}.
This PR updates the
?data.tabledocumentation to clarify how per‑groupjresults are combined whenbyis used.The new paragraph explains that
jis evaluated once per group and the results are bound row‑wise usingrbindlistwithuse.names = FALSE, so columns are matched by position and the first group’s column names are kept. This makes the behavior in cases like #7643 explicit.A small test in
tests/by-rbindlist-use-names-false.Ris given to capture the current behavior so the documentation and implementation stay in sync.Closes #7643.