Understanding examples from the tidyeval cheatsheet

I'm one of those people (~1 year R experience) who spent weeks trying and failing to understand tidyeval while trying to write tiny dplyr utility functions for the first time, and used to re-read the programming w/ dplyr vignette incessantly over hours/days. So this new RStudio tidyeval cheatsheet has been an amazing and extremely helpful resource for me, giving me a one-shot, 2-second glance to remind myself about everything core I use and encounter in my regular code/use-cases.
Tidyeval Cheatsheet

Because the second page's recipes don't have example inputs/outputs I can check in-console, I have a few residual questions about my understanding of the sheet's 'Programming Recipes' section from the second page (apologies for the long play in 3 acts that follows..):

1 - 'Writing a function that recognizes quasiquotation'
Why is this the title? The example appears to evaluate a quoted input, and !! isn't used within a quoting function, such that I'd definitively mark/recognize that in my mind as quasiquotation.

2 - 'Pass to Argument Names of a Quoting Function'
As far as I understand the critical difference between ensym and enexpr functions is that unquoting/evaluating contents lead to either a symbol a+b or the result of adding variables a and b together. Assuming that's right, why does the example detail a variable called name that is unquoted but never seen declared elsewhere in the same example? I'm also slightly lost about why var was handled by ensym here but enquo in the adjacent example. If there's a variable name called a+b that conflicts with other variables in the environment that would be evaluated this makes sense, but otherwise it's confusing for me.

3 - 'Modify User Arguments'
What would be some sample code and output that would go here? It looks like an expression is formed that merges the contents of two quoted expressions together, where maybe f is a+b and v is +d+e, but I'm not sure. I've never used quasiquotation that way back to back, i.e. quoting_function((!!f)(!!v))

Some other examples are difficult but I get the broad strokes of them, whereas these were the pieces I don't think I can quite grok by just guessing and checking with R on my own.

Thanks so much again for writing this reference :pray:

The tidyeval reference here gives a more verbose explanation for all of these:

1 Like

Thanks so much Mara!

I'm still confused about certain parts of the cheatsheet recipes like the use of ensym(), but this definitely addresses all the concepts I was looking at, especially sections 5.1.3 and 5.2. :pray:

Especially since it's a new cheatsheet, you could file an issue in the rstudio/cheatsheets repo if you think there's an error in the examples.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.