-
Notifications
You must be signed in to change notification settings - Fork 1k
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
nested ':=' reference assignment fails #6768
Comments
There is a workaround of returning a DT containing the results of the inner and outer function and assigning them all at once, however this structure was more desirable. |
could you confirm (1) whether the issue is present on CRAN (2) whether updating to the current version of data.table fixes the issue? There are some recent related commits that might fix it |
Thank you, the latest CRAN does indeed resolve this issue! |
Great! Please also check on the current devel version, this is probably due to #6551 |
I see the same behavior on 1.16.0, 1.16.4 and current
It's definitely odd that you've managed to create a column that's just Could you double check & report which version produces the correct result? |
I went back as far as 1.13.0 and was unable to find a version that produces the correct result, however I believe I found the root of the confusion:
The second occurrence of the assignment statement produces the correct result. I believe this is what occurred when I first tested the latest CRAN version. |
*Followed TODO: by mattdowle from resolution to '2-space indentation Rdatatable#2420' *Added tests for jsub that modify DT by-reference *Added test case for interger vector indexing
I'm surprised you would expect this to work at all. Shouldn't it be |
I would expect dt[, new:=outer(dt)] to create 2 new columns one called 'new' with the return value of outer, (11:20) and another "side-effect" column, called 'se', with the values of 1:10 as created in the inner function. Calling only outer(dt) would creates the column 'se' correctly, however the return value of outer() is lost.
|
The result I would expect would be the following:
|
Thanks for more detail. If just running |
The original example included an assignment to the column 'se' and 'new' 1.) column se should be created with values 1-10 here 2.) the outer function returns the values 11-20 which should be assigned to new 3.) the return value of outer is assigned to new The original example:
The results of the above snippet were:
The results I expected were:
I found that this occurs because the evaluation of the left-hand side at points (#1, & #3) both occur at the point when dt only contains the column 'a'. This leads to both new columns being assign the following available integer index, i.e '2' Hopefully this was a more complete explanation of the bug. Please let me know is there are any other questions, confusion or concerns with the PR! |
Issues arise when a function is called with the reference assignment operator ':=', which in-turn modifies the dt by reference as well. Below is the example running on the latest dev version. The result of the outer function overwrites the inner function in the incorrect column named 'se', the column named new is left empty.
The text was updated successfully, but these errors were encountered: