Skip to content

Instantly share code, notes, and snippets.

@reinholdsson
Last active January 6, 2023 12:08
Show Gist options
  • Save reinholdsson/1c2aec91853b767fc3ce942e3e33f8a9 to your computer and use it in GitHub Desktop.
Save reinholdsson/1c2aec91853b767fc3ce942e3e33f8a9 to your computer and use it in GitHub Desktop.
dplyr, rlang, etc.
library(dplyr)
df <- nycflights13::flights
.a <- quote(sched_dep_time + dep_delay)
.b <- function() quote(sched_dep_time + dep_delay)
.c <- function(x) bquote(.(substitute(x)) + dep_delay)
.d <- function(x) {
x <- enquo(x)
expr(!!x + dep_delay)
}
.e <- function(x) {
expr(!!x) # + dep_delay
}
.f <- function(x) x
df %>%
mutate(
a = !!.a,
b = !!.b(),
c = !!.c(sched_dep_time),
d = !!.d(sched_dep_time),
e = .e(sched_dep_time),
f = .f(sched_dep_time)
) %>%
select(a, b, c, d, e, f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment