A talk given at the Eugene R Users Meetup, May 8 2018.
I'll start with a common question for new R users: When do I put quotes ("
) around something in R? I'll give you a few strategies for identifying whether you need quotes, backticks, or nothing at all.
Then we'll transition to talking about quotation, which by the way, doesn't mean surrounding something in quotes. What does it mean? You'll learn what quotation is, and why developers use it to make your life easier.
Finally, I'll introduce the idea of unquoting and help you understand what it means when a function says it supports quasiquotation. This will allow you to to use functions like dplyr::filter()
inside your own functions.
I'll aim to have the talk be interactive without you having a laptop with you, but if you would like to follow along in R, make sure you have the tidyverse packages, rlang and lobstr installed:
install.packages(c("tidyverse", "rlang"))
# install.packages("devtools")
devtools::install_github("r-lib/lobstr")
We worked through three examples:
- Using a dplyr function interactively
- Using a dplyr function with a saved variable
- Using a dplyr function inside a function
See the annotated output or source, or motivating slides.
This meant I omitted the "Quotes" part of the talk, but you can look at my notes.
If dplyr is new to you, start by learning to use it interactively with the Data Transformation chapter in R for Data Science.
If you have never written your own function before, start with Functions in R for Data Science or DataCamp's Writing Functions in R.
If you've written functions but want to formalise your knowledge, Functions in Advanced R.
If you want to see how to program with dplyr functions, the Programming with dplyr vignette.
If the vignette seems a little unapproachable, find another resource in Mara Averick's roundup of tidy eval resources.
If you'd prefer to watch than read, the RStudio's tidy evaluation webinar, or Hadley's tidy evaluation in 5 minutes.
If you are interested in the underpinnings, and possibly using tidy evaluation ideas in your own packages, look at Metaprogramming in the new (in progress) edition of Advanced R.
Quotes, Quotation and Quasiquotation by Charlotte Wickham is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.