-
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
Overbroad issue about .. being defined in calling scope? #2988
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I wrote a .. <- function (x, env = parent.frame())
{
stopifnot(inherits(x, "character"))
stopifnot(length(x) == 1)
get(x, envir = parent.env(env))
} It is useful when the variable names are duplicate with data.table col names. for example. library(data.table)
a <- data.table(x=1:2,y=2:1,z=c("x","y"))
x <- "y"
# works in `i`
a[get(..("x")) == 1] # a subset when `y==1`
a[..x==1] # Error in eval(.massage i(isub), x, parent.frame()) : object '..x' not found
a[get(..x)==1] # Error in get(..x) : object '..x' not found
# works in `j`
a[, get(..("x"))] # a vector of the col `y`
a[, ..x] # a data.table with col `y` Although we need use the additional a[z==..("x")] # a subset data.table when `z=="y"`
a[, z==..("x")] # a logical vector for `z=="y"` Back to the question of @MichaelChirico, if we replace I also found that the a[, ..("x"):=9] # Error in get(x, envir = parent.env(env)) : object 'x' not found
a[, get("x"):=9] # the `y` will be replaced with 9 And it does not work in a[, .N, by=..("x")]# Error Last year, I put this solution in SO, The old version of `..old` <- function(x){
stopifnot(inherits(x, "character"))
stopifnot(length(x)==1)
get(x, parent.frame(4))
} The old version worked fine in data.table 1.10.4, but when I updated to 1.11.4, it failed in In my opinion, maybe the Could we have an official support for Thanks! |
|
I stumbled over the same warning message as Michael. I doubt my example contains any additional information to this issue, but since it was so simple I thought I just as well could add it here for illustration. I wanted to update certain rows in certain columns with values from other rows in the same columns. Stripped down version:
|
SO post to update (exactly the same as Henrik's above): https://stackoverflow.com/a/53180736 Another: https://stackoverflow.com/q/53227216 |
Any progress on this issue? I also get the warning |
I will add my two cents having also run into these issues... @liqg, However, it seems to me that |
related: https://stackoverflow.com/questions/57737697/how-to-use-data-table-a-reactive-expression-in-shiny DT[, ..input$var] |
Although, there is an alternate.
|
I feel I'm very familiar with data.table and use it every day, still I often need to check reference or my own notes when I need to use variable for column names. The Recently I saw |
@dracodoc there is a new feature coming to address what ..prefix is meant to help with. You write variable name as is, and then just redefine it via new arg |
Thanks, do you mean something like this? I may have the variable defined somewhere already, for example I have a function to process a column in dt convert_col <- function(dt, col_name) {
# how should I write this?
dt[, col_name := xxxx, env = list(col_name = col_name)]
}
All we need is just to recognize that some variables are from outside of dt scope... |
If you are passing character scalar into |
Just encountered this...
Yes,
idx
and..idx
exist in calling scope, but..idx
appears "down a level" (reverting to the analogy of..
as "up a level"), so the code as written seems pretty natural to me.I get where the message comes from, and I'm not sure how much effort it's worth to fully account for this type of possible nesting, but wanted to raise attention anyway.
To get rid of this warning, I'm resorting to
with = FALSE
, so this is related to #2826This becomes an error if there's no
idx
in globalenv:The text was updated successfully, but these errors were encountered: