-
Notifications
You must be signed in to change notification settings - Fork 978
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
Inconsistent behaviour when adding columns by reference in chains #1525
Comments
It works, it just updates the subset, as you could |
@DavidArenburg Thanks. This is a minimal example of a more complicated task ( Anyway I now see the logic. I'm closing the issue as this is considered expected behaviour. |
I am reopening this with an updated title. See updated minimal example require(data.table) ##v1.9.6 or v1.9.7
dt <- data.table(a = 1:3)
dt[a<3, ][a<2, b := 1]
dt ## As the initial example, original dt remains unaltered
# a
# 1: 1
# 2: 2
# 3: 3 However... dt[a<3, c := 3][a<2, b := 1]
dt ##dt has now been updated
# a c b
# 1: 1 3 1
# 2: 2 3 NA
# 3: 3 NA NA I think that for consistency both operations should behave the same |
They should not behave the same if there is |
As an addiitional hint, consider this: dt <- data.table(a = 1:10, b = 1:10)
address(dt)
# [1] "0x4e6ed00"
address(dt[a<3])
# [1] "0x5d553e0"
address(dt[a<3, c:= 1])
# [1] "0x4e6ed00"
|
@jangorecki Yes. However when At the moment |
Ok, sounds more like you have a documentation request than a finding of "inconsistent behavior". One wrinkle is that |
@franknarf1 Although I now can see how and why this is as it is, from my 'end-user' perspective, |
The dt[TRUE==FALSE, z := 1][] # results full datasets
dt[TRUE==FALSE] # results 0 rows dataset |
Ok. I think I see your point. However, it's just basic R syntax that
is equivalent to
and not to Said another way,
can be extended to
Oh and it might as well mention the new |
This issue seems to boil down to duplicate of #905. PRs are of course welcome. |
See minimal example below
If this is intended behaviour could you please add a warning that "new columns have not been assigned" or something along the lines?
The text was updated successfully, but these errors were encountered: