Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why to quote in dplyr and why not to quote in dplyr?

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading