Clarifying question - When is manual data mask needed in `rlang::eval_tidy`?

Since you've already read the material in Advanced R, I'm lifting some relevant sections from the Create a data mask sectiion of the rlang documentation.

Many R functions evaluate quoted expressions in a data mask so these expressions can refer to objects within the user data.

Obviously not a home run answer, since "many R functions" could mean a lot of things, but ¯\(°_o)/¯

Most of the time you can just call eval_tidy() with user data and the data mask will be constructed automatically.

^^ is in the preface describing that, largely, the manual construction of data masks is meant for developers of tidy eval interfaces, as opposed to users.

There are three main use cases for manual creation of data masks:

  1. When eval_tidy() is called with the same data in a tight loop. Tidy eval data masks are a bit expensive to build so it is best to construct it once and reuse it the other times for optimal performance.
  2. When several expressions should be evaluated in the same environment because a quoted expression might create new objects that can be referred in other quoted expressions evaluated at a later time.
  3. When your data mask requires special features. For instance the data frame columns in dplyr data masks are implemented with active bindings.

This thread contains some good info re. providing the .data pronoun manually (referencing Programming with dplyr | Programming recipes) :

1 Like