etiennebacher commented on PR #46667: URL: https://github.com/apache/arrow/pull/46667#issuecomment-2930618433
> in case_when(), where we have the code mask <- caller_env(), maybe instead we actually want mask <- caller_env(n=2) or something like that, because if that works we've got less risk of unintended consequences? Thanks for the detailed reasoning. I should have probably explained a bit more what I had tried. I thought using `caller_env(2)` would easily solve the issue, but it turns out this generates a warning, in addition to the original error (I locally reverted the change in `arrow_eval()` so I'm basically using the `main` branch): > Passing an environment as data mask is deprecated. Please use `new_data_mask()` to transform your environment to a mask. > > env <- env(foo = "bar") > > # Bad: as_data_mask(env) eval_tidy(expr, env) > > # Good: mask <- new_data_mask(env) eval_tidy(expr, mask) This doesn't make any sense to me, `caller_env()` and `caller_env(2)` both return an environment, but only the latter triggers this warning. I tried to play with the `n` in `caller_env()`, with the parent environments, but nothing worked. In the end, I tried this: - I put `browser()` after `mask <- caller_env()`, ran `source("foo.R", local = new.env())`, and exported its value with `mask_local <<- mask` - did the same with `source("foo.R")` and exported the value to `mask_global` (it's important to do local first, and then global). Here's the output of `waldo::compare()`: ```r > waldo::compare(mask_global, mask_local) `old$.data$x$.:xp:.` is <pointer: 0x000001b2a2bee6d0> `new$.data$x$.:xp:.` is <pointer: 0x000001b2a2bee330> `old$.data$x$schema$.:xp:.` is <pointer: 0x000001b2a2bee7d0> `new$.data$x$schema$.:xp:.` is <pointer: 0x000001b2a2bee3d0> `old$.data$x$schema$fields[[1]]$.:xp:.` is <pointer: 0x000001b2a2bee350> `new$.data$x$schema$fields[[1]]$.:xp:.` is <pointer: 0x000001b2a2bee650> `old$.data$x$schema$fields[[1]]$type$.:xp:.` is <pointer: 0x000001b2a2bee750> `new$.data$x$schema$fields[[1]]$type$.:xp:.` is <pointer: 0x000001b2a2bee870> `parent.env(old$.env)` is <env:global> `parent.env(new$.env)` is <env:0x000001b2a6293438> `parent.env(old$.top_env)` is <env:global> `parent.env(new$.top_env)` is <env:0x000001b2a6293438> ``` I see that the parent environment is different, but I can't figure out where this could be fixed. I'm open to suggestions on this, I agree that modifying `eval_tidy()` just for this is a bit clumsy. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org