data.table::.N may not work as expected in several places

Open
#5,958 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
30/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
r

Research direction

Reproduce the reported difference between .N and data.table::.N, then inspect the j evaluation and GForce eligibility discussed in the issue and related tests for #5955. Decide between rejecting qualified NSE placeholders and removing data.table:: before evaluation; done means the chosen behavior is implemented, documented, and covered by tests.

Written by the indexing model from the issue text.

Description

consistency
DT = data.table(a = rep(1:5, 2L), b = 1:10)
DT[, b[.N]]
# [1] 10
DT[, b[data.table::.N]]
# integer(0)

Of course .N is populated to the .SD environment, but in evaluation this will pull the NULL value exported by data.table.

Noticed while writing tests for #5955.

We can:

  1. Just disallow this use case, explicitly documenting that data.table::.N is not supported & you must use .N alone. We could even do delayedAssign(".N", stop("Don't reference .N directly.")). Would need to investigate if importFrom(data.table, .N) triggers the delayed assignment.
  2. Massage j up front to remove data.table:: from any NSE placeholders. This will bea new (ideally small) overhead in j for all queries, though. That would obviate #5955, as by the time we start checking jsub for GForce eligibility, data.table:: will already be removed.
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.