I think the documentation might have been updated since the question was asked, but for new visitors, the relevant part of the rlang documentation for as_data_mask is:
parent Soft-deprecated. This argument no longer has any effect. The parent of the data mask is determined from either:
- The env argument of eval_tidy()
- Quosure environments when applicable
So in the case of eval_tidy(myquo, data = as_data_mask(list(), parent = e))
the env
of eval_tidy and the quosure env on myquo
are both the global env, and the data mask itself is empty, hence why Temp
is not found.
eval_tidy(myquo, data = as_data_mask(datasets::airquality))
works but has an unnecessary call in it, since the data argumnet of eval_tidy will convert a data.frame to a data mask anyway, so the easiest way would be.
eval_tidy(myquo, data = datasets::airquality)
On the other hand, if you really want to specify the environment explicitly in eval_tidy
, you could use expr
instead of quo
myexpr <- expr((Temp - 32) / 1.8)
eval_tidy(myexpr, data = as_data_mask(list(), parent = e)) # still fails since parent is overridden
eval_tidy(myexpr, data = list(), env = e) # works since there's no quosure env to override env