-
Notifications
You must be signed in to change notification settings - Fork 977
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
weird exception when by contains get #1985
Comments
This arose for me in a real but more complex setting, where I wanted to update and aggregate in one go, and pass a column name as a parameter, e.g. |
This bug occurred for me in a real-world situation today. I would like to add my minimum reproducible example that I typed up before finding your post.
|
@mhdann thank you for providing your example, as a workaround you can currently use ans = dtIris[Sepal.Length > 4, .N, by = c(speciesVar, "Petal.Width")]
setnames(ans, speciesVar, "var") This kind of parameter substitution is well addressed by pending PR #4304 dtIris[Sepal.Length > 4, .N, by = .(var = .speciesVar, Petal.Width),
env = list(.speciesVar = speciesVar)] |
Thank you for raising this issue. I can offer a few responses based on the example that @mhdann provided. First, let's start with the portion of code that leads to the error message:
The last line produces the following error message:
I think this error is triggering because the data.table is looking for speciesVar in the outside environment. You would trigger the same kind of error message with:
In addition to the suggestions above, I can offer a few other workarounds:
In this example, using get() statements for each of the variables in the by step ensures that both sub-objects of the list are the same length. Alternatively, the getDTeval package can be used to translate the get() statements before evaluation.
Finally, you could also work around the issue with:
In this case, the by step is invoking an outside call to dtiris, which is not efficient. |
Check out new env argument, addresses such problems in a much cleaner way dtIris[Sepal.Length > 4, .N, by = .(var = speciesVar, Petal.Width), env=list(speciesVar="Species")] you can even pass column name |
Just copied my question on stackoverflow:
get
function usually works without problems in data.table, but I am not able to understand the reason of this bug.(I use R version 3.3.2 and data.table version 1.9.6.)
The text was updated successfully, but these errors were encountered: