I am teaching an intro to R course and a student asked me a question that I cannot answer.
The question is, why do we not put id and sex in quotes after select in this example
df1 %>%
select(id, sex)
but we put id in quotes after inner_join in this example
df1 %>%
inner_join(df2, by = 'id')
The best I could come up with is because it id is after an = sign. But I imagine there is a better answer.
>Solution :
Reference for tidy evaluation: https://dplyr.tidyverse.org/articles/programming.html
Spec for inner_join: https://dplyr.tidyverse.org/reference/mutate-joins.html
Basically, inner_join‘s by = argument takes "A join specification created with join_by(), or a character vector of variables to join by."
# character vector is your provided example
df1 %>%
inner_join(df2, by = 'id')
# works
# join_by() form uses tidy evaluation
df1 %>%
inner_join(df2, by = join_by(id))
# also works