x[i, j, by=.] where `i` is a data.table and `j` contains expressions from `i` should/could work as well

Open
#733 29 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Stale
Tech stack
r
Domain
data

Research direction

Start by running the two R examples in the issue and compare the join-and-grouping result with the explicitly chained form. Trace the data.table join and j/by evaluation paths to understand where expressions from the joined table are resolved; done means the valb case behaves equivalently without breaking the existing vala example.

Written by the indexing model from the issue text.

Description

feature request joins

Referring to this SO post from @juancentro:

dta <- data.table(idx=1:3, vala=4:6, fidx = c("a", "a", "b"), key="idx")
dtb <- data.table(idx=c(1,4), valb=c(10,11), key="idx")

# (1)
dta[dtb, sum(vala), by=fidx]
#    fidx V1
#1:    a  4
#2:   NA NA

# (2)
dta[dtb, sum(valb), by=fidx]
# Error in `[.data.table`(dta, dtb, sum(valb), by = fidx) : 
#   object 'valb' not found

It would be nice to have case (2) returning the right result as well.

That is, as @juancentro and @eantonya mentioned:

dta[dtb, sum(valb), by=fidx] == dta[dtb][, sum(valb), by=fidx]

would be great!

Thanks to @juancentro for reporting on SO.

Dominant language
R
Stars
3.9k
Forks
1.1k
Avg merge
14h 4m
Merged PRs (30d)
4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Rdatatable/data.table

All issues in Rdatatable/data.table

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.