"nomatch is ignored with :=" warning is misleading

Open
#2,180 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
r
Domain
data

Research direction

Start by reproducing the supplied [.data.table examples with nomatch=0 and :=, then trace where the warning is emitted. Update the warning so it reflects the demonstrated effect of nomatch, and add or adjust coverage for both examples to verify the resulting rows and warning behavior.

Written by the indexing model from the issue text.

Description

bug joins

Starting in v1.9.8 this warning appears when using := with nomatch=0:

nomatch isn't relevant together with :=, ignoring nomatch

However, when I removed all the nomatch=0 from := calls in my code it caused me some issues. So I thought it was worth pointing out that the warning is not strictly true (nomatch might still be relevant in := calls; nomatch is not ignored). An illustrative example run on v1.10.4:

DT<-data.table(x=2:5)
X<-data.table(x=1:4)

DT[X, on='x', y:={ print(length(x)) ; x }]
# [1] 4

DT[X, on='x', y:={ print(length(x)) ; x }, nomatch=0]
# [1] 3
# Warning message:
# In `[.data.table`(DT, X, on = "x", `:=`(y, { :
#   nomatch isn't relevant together with :=, ignoring nomatch

Above, the resulting data.table is the same, but nomatch controls whether the elimination of unmatched rows occurs in j or only on assignment. This can be relevant: it caused problems in my code when I used vectors in j that weren't in either data.table (x or i). For example:

DT[X, on='x', y:=1:3 + x, nomatch=0][]
# assume this is desired behavior
#    x  y
# 1: 2  3
# 2: 3  5
# 3: 4  7
# 4: 5 NA
# Warning message:
# In `[.data.table`(X, DT, on = "x", `:=`(y, 1:3 + x), nomatch = 0) :
#   nomatch isn't relevant together with :=, ignoring nomatch

DT[X, on='x', y:=1:3 + x][]
# results are incorrect without nomatch=0
#    x  y
# 1: 2  4
# 2: 3  6
# 3: 4  5
# 4: 5 NA
# Warning message:
# In 1:3 + x :
#   longer object length is not a multiple of shorter object length

Thus there remains a use case for using nomatch=0 with :=, and I don't think users should be told that it is not relevant (and definitely shouldn't be told that it is ignored). Could lead to hard-to-find problems if people assume, like I did, that there are no possible repercussions to removing nomatch=0 where := appears in their code.

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.